Reputation: 11
I am trying to read input string from keyboard and write it into a text file called dFile.txt in my program using fputs(). Since fputs() don't add new line i have explicitly added new line in my code but when i check my output file it did not add any new line. I have added tab "\t" just to cross check if note pad dont recognize any special character but it is working fine with it.
#include<stdio.h>
#include<string.h>
int main()
{
char arr[100];
FILE *dest;
dest=fopen("dFile.txt","w");
puts("enter the string");
while(strlen(gets(arr))>0)
{
fputs(arr,dest);
fputs("\n",dest);
fputs("\t",dest);
}
fclose(dest);
return 0;
}
Upvotes: 0
Views: 2175
Reputation: 23670
Notepad recognizes a \r\n
(carriage return, followed immediately by newline) as a line break. Although, some other editors might recognize a \n
by itself, as do all Unix utilities.
Also (and more importantly): it's not a good idea to use gets
for unknown input sources.
Upvotes: 2