The code is supposed to define a file pointer called "fpwrite"
open a text file called "sppdata.txt"
and check to see if the file is opened and use it to write "Hello Sara" a hundred times. I am missing a couple of things I think.
The code is supposed to define a file pointer called "fpwrite"
open a text file called "sppdata.txt"
and check to see if the file is opened and use it to write "Hello Sara" a hundred times. I am missing a couple of things I think.
You're missing a for loop which loops 100 times, and a fprintf() call inside that loop
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Code:#include<stdio.h> #include<string.h> int main(void) { char name[31] = "Hello Teri"; FILE *fpwrite; int i; fpwrite=fopen("cppdata.txt" , "w"); if (fpwrite==NULL) { printf("cannot open or create file.\n"); } else { for (i=0;i<100;i++) { fprintf(fpwrite,"%s\n",name); } fclose(fpwrite); } return 0; } /*main*/