Write to a Text File in Batch Mode using the function fputs() - C File

C examples for File:Text File

Description

Write to a Text File in Batch Mode using the function fputs()

Demo Code

#include <stdio.h>

int main(){// ww  w.  jav  a 2 s . c om
     int k = 0;
     FILE *fptr;
     fptr = fopen("C:\\Code\\data.txt", "w");

     if (fptr != NULL) {
          puts("File opened successfully.");
          fputs("asdf.\n", fptr);
          fputs("1234.\n", fptr);
          k = fclose(fptr);
          if(k == -1)
            puts("File-closing failed");
          if(k == 0)
            puts("File is closed successfully.");
     }
     else
          puts("File-opening failed");
     return(0);
}

Result


Related Tutorials