Skip to content

Instantly share code, notes, and snippets.

@cgmb
Created September 22, 2015 16:47
Show Gist options
  • Save cgmb/e42262d341b4f19274b0 to your computer and use it in GitHub Desktop.
Save cgmb/e42262d341b4f19274b0 to your computer and use it in GitHub Desktop.
strcpy example
#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