What I want to do is the following:
- read 1st line from file.txt
- remove the \n from it.
- print it
For that purpose, my code is:
main(){
char line_one[100];
FILE *fp;
fp = fopen("file.txt", "r");
fgets(line_one, sizeof line_one, fp);
printf("%s", line_one);
char line_one_NEW[100];
strncpy(line_one_NEW, line_one, strlen(line_one)-1);
printf("%s", line_one_NEW);
return 0;
}
The result that I am getting is:
test
test�{r
Why is there strange stuff after the line_one_NEW ?