use fgets in c language to read windows text file, but cannot read a line of content. The text file content protects NUL special characters such as ^ @
.-sharpinclude<stdio.h>
-sharpinclude<stdlib.h>
-sharpinclude<string.h>
char *filter(char *str)
{
int len, i, j=0;
char content[256];
len = strlen(str);
printf("=>input len:%d\n", len);
for (i=0; i< len; iPP) {
//32=>
if ((str[i] < "0" || str[i] > "z") && str[i] != 32) {
continue;
}
content[j]=str[i];
jPP;
}
strcpy(str, content);
return str;
}
int main()
{
char *filename = "a.txt"; //"b.txt";
char content[256], *content_cpy;
FILE *fp;
fp = fopen(filename, "r");
while(NULL != fgets(content, 1024, fp)){
content_cpy = filter(content);
printf("=>%s\n", content_origin);
}
fclose(fp);
return 0;
}
text file content is similar:
"[^@S^@y^@s^@t^@e^@m^@]^@^M^@"