i am dealing with the file io functions,can any one explain me the use & working of the statement 2,in the following code,here i want to enter string,&then want to write it on a disk…..
#include<stdio.h>
#include<sttring.h>
int main()
{
FILE *fp;
char s[80];
fp=fopen("noname00.cpp","w");
while(strlen(gets(s))>0) /*parenthesis now at correct place*/ /*purpose of this statement */
{
fputs(s,fp);
fputs("\n",fp);
}
fclose(fp);
return 0;
}
Simple but to the point help would be appreciated.
Which one exactly is statement 2?
char s[80];? It simply declares and defines a character array of size 80.If you mean statement 2 is
while(strlen(gets(s)>0)), it doesn’t look correct to me. strlen() accepts aconst char *as its argument but you are specifying it an integer instead:gets(s) > 0.Also, never use
gets()because http://c-faq.com/stdio/getsvsfgets.htmlAlso, get a copy of http://en.wikipedia.org/wiki/The_C_Programming_Language and study.