行长不超过 254 应无问题。
fgets 获得的字符串含结尾处的 '\n',
用 temp[tempLength]='\0'; 可以去掉。
strncpy(tempCopy,temp,tempLength); 第一个参数 你少写了一个p.
用 strcpy(tempCopy,temp); 也可以。
================================
根据猜测,写了个全程序:
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *fp;
char temp[256];
char name[256],country[256];
fp=fopen("abc.txt","r");
while(fgets(temp,256,fp) != NULL){
int tempLength = strlen(temp);
char *tempCopy = (char*) calloc(tempLength+1,sizeof(char));
temp[tempLength]='\0';
strcpy(tempCopy,temp);
sscanf(tempCopy,"%s %s",name,country);
printf("%s\n", name);
printf("%s\n", country);
}
fclose(fp);
return 0;
}