Skip to content

Instantly share code, notes, and snippets.

@arafatkamaal
Created August 23, 2013 09:56
Show Gist options
  • Save arafatkamaal/6317576 to your computer and use it in GitHub Desktop.
Save arafatkamaal/6317576 to your computer and use it in GitHub Desktop.
Copying and printing character arrays
#include<stdio.h>
#include<string.h>
#define FIRST "hello world"
#define SECOND "bye"
int main()
{
char message[500];
//strncpy(message, FIRST, 12);
strncpy(message, FIRST, sizeof(FIRST));
char* ptr;
ptr = message;
while(*ptr != '\0')
{
printf("%c",*ptr);
ptr++;
}
printf("\n");
strncpy(message, SECOND, sizeof(SECOND));
ptr = message;
while(*ptr != '\0')
{
printf("%c",*ptr);
ptr++;
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment