if I wanna copy a part of the string to another string.
It is my code, Is it OK? but I have a core dump.
include<stdio.h >
int main()
{
FILE *fp;
fp = fopen("test.txt ","r");
char s1[20],s2[5],s3[2];
fscanf(fp,"%s", s1);
printf("s1 is %s\n",s1);
int i;
for(i=0;i<6;i++ )
{
s2[i] = s1[1+i];
}
s2[6]='\0';
printf("s2 is %s\n",s2);
s3[0]=s1[10];
s3[1]=s1[11];
s3[2]='\0';
printf("s3 is %s\n",s3);
fclose(fp);
}
Comment