Skip to content

Instantly share code, notes, and snippets.

@photex
Created January 19, 2011 15:54
Show Gist options
  • Save photex/786345 to your computer and use it in GitHub Desktop.
Save photex/786345 to your computer and use it in GitHub Desktop.
see what happens
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
char *src="12345678";
char dst1[10];
char dst2[10];
// ensure that dst is clean
memset(dst1, '\0', 10);
memset(dst2, '\0', 10);
strcpy(dst1, src);
strncpy(dst2, src, 8);
printf("Source: %s\nResult 1: %s\nResult 2: %s\n", src, dst1, dst2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment