Created
September 22, 2015 16:47
-
-
Save cgmb/e42262d341b4f19274b0 to your computer and use it in GitHub Desktop.
strcpy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main() { | |
char buffer[6]; | |
char* h = "hello"; | |
// copy the string from 'h' into 'buffer' | |
strcpy(buffer, h); | |
// now change the first letter in the buffer | |
buffer[0] = 'j'; | |
int result = strcmp(buffer, h); | |
if (result == 0) { | |
printf("They match!\n"); | |
} else { | |
printf("They do not match!\n"); | |
printf("Expected: %s\nActual: %s\n", | |
h, buffer); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment