C Programme এ কোনো file থেকে কিভাবে information নিব?

কোনো একটি file এ এ রুপ information আছে  :

Name  Age
Rahim 22
Karim 19
Asif 24
Saif 28
 

                                   বা, 

  

Rahim = 22;

Karim  = 19;

Asif      = 24;

Saif      = 28;

    

* কোনো একটি programme এ কিভাবে ওই file এর information  ব্যবহার  করতে পারবো। 

                                  (Programme টি লিখে বোঝাবেন please)  

2926 views

1 Answers

  1. // file থেকে read

  2. #include
  3. #include
  4.  
  5. int main()
  6. {
  7.    char ch, file_name[25];
  8.    FILE *fp;
  9.  
  10.    printf("Enter name of a file you wish to see\n");
  11.    gets(file_name);
  12.  
  13.    fp = fopen(file_name, "r"); // read mode
  14.  
  15.    if (fp == NULL)
  16.    {
  17.       perror("Error while opening the file.\n");
  18.       exit(EXIT_FAILURE);
  19.    }
  20.  
  21.    printf("The contents of %s file are:\n",file_name);
  22.  
  23.    while((ch = fgetc(fp)) != EOF)
  24.       printf("%c", ch);
  25.  
  26.    fclose(fp);
  27.    return 0;
  28. }
2926 views Answered

Related Questions

Next steps