Problem
Write a C program that prompt the user to input a poem line by line. The program creates a file named poem.txt and writes that poem in that file. Use fputs function.Solution - Code
#include<stdio.h>#include<stdlib.h>
int main()
{
char s[80];
FILE *ft;
int i;
printf ("NOTE: If you want to exit just press enter twice.\n\n");
ft = fopen ("Poem.txt","w");
printf ("Enter Poem : ");
while (1)
{
gets(s);
if (strlen(s) == 0)
break;
else
fputs(s,ft);
}
fclose(ft);
return 0;
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.