Program to read data from text file


C File =>



/* A file “student.txt” contains roll no, name and total_marks. Write a program to read this file to display all student details on screen. */


#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    int rno,total;
    char nm[30];
   fp=fopen("student.txt","r");
   if(!fp)
      printf("\n Error in reading...");
   else
  {
      do
     {
          fscanf(fp,"%d %s %d",&rno,nm,&total);
          printf("\n\n Data in file : \n Roll no\t Name\t Total\n");
          printf("%d\t%s\t%d\n",rno,nm,total);
      }while(!feof(fp));
}
return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.