Contoh Program C - #10 Sequential File Read Write Text


 #include <stdio.h>  
 #include <string.h>  
 char string[225];  
 char name_file[225];  
 void read();void write();  
 main()  
 {  
      printf("\n\nNama : Timothy Kawulusan \nNIM : 1101164456\n\n");  
      printf("-----------------------------------------------\n");  
      printf("Masukkan nama file:\t");gets(name_file);  
      write();  
      system("pause");  
      read();  
 }  
 void write ()  
 {  
      printf("Ketik text disini:\n");  
      FILE *data;  
      strcat(name_file,".txt");  
      data = fopen(&name_file,"w");  
      gets(string);  
      fprintf(data, "%s\n", string);  
      fclose (data);  
 }  
 void read()  
 {  
      FILE *data;  
      data = fopen(&name_file, "r");  
      while (fgets(string, sizeof(string), data) != NULL)  
      printf("%s",string);  
      fclose (data);  
 }  

Komentar

Postingan populer dari blog ini

Kegunaan Sensus Penduduk