Advertisement
Sierra_ONE

FileRecord.c

Feb 27th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct {
  4.     char lname[16];
  5.     char fname[24];
  6.     char mi;
  7. }Nametype;
  8. typedef struct {
  9.     Nametype name;
  10.     unsigned int ID;
  11.     char course[8];
  12.     int yrlvl;
  13. }Studtype;
  14.  
  15. void displayStud(Studtype stud);
  16.  
  17. int main (void){
  18.     Studtype studs[5] = { { { "Detablan", "Paul", 'M'}, 11111111, "BSCS", 1},
  19.                         { { "Monsalud", "Liv", 'B'}, 11111111, "BSCS", 1},
  20.                         { { "Dejito", "Christine", 'P'}, 11111111, "BSCS", 1},
  21.                         { { "Antonio", "Justin", 'M'}, 11111111, "BSCS", 1},
  22.                         { { "Quitayen", "Moises", 'X'}, 11111111, "BSCS", 1} };
  23.  
  24.     FILE *fp;
  25.     char filename[16];
  26.     int x;
  27.     for(x=0;x<num;x++){
  28.     displayStud(studs[x]);
  29.     }
  30.    
  31.     printf("\nEnter the name of the file: "); scanf("%s", filename);
  32.    
  33.     // createFile.c Program
  34.     fp = fopen(filename, "w");
  35.     if(fp == NULL){
  36.     printf("\nUnsuccessful in opening %s", filename);  
  37.     }else{
  38.         fwrite(stud, sizeof(Studtype), 1, fp);
  39.         fclose(fp);
  40.     }
  41.  
  42. return 0;
  43. }  
  44.  
  45. void displayStud(Studtype S){
  46. printf("%")
  47. }
  48. //readFile.c Program
  49. /*
  50.     printf("\nEnter the name of the file: "); scanf("%s", filename);
  51.    
  52.     // createFile.c Program
  53.     fp = fopen(filename, "r");
  54.    
  55.     while (fread(&S, sizeof(S), 1, fp) != 0){
  56.     displayStud(S);
  57. }
  58. fclose(fp);
  59.  
  60. void displayStud(Studtype S){
  61.    
  62. }*/
  63.  
  64.  
  65. //writeFile.c Program
  66. /*int num = sizeof(studs)sizeof(stud[0]);*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement