FY_BCA_C_SLIP 27_2



slip no : 27_2 create structure student having fields roll noand name.
accept details of student fom th use store it into the file and calculate the size of file */


#include<stdio.h>
#include<stdlib.h>

struct student
{
int roll_no;
char s_name[20];
}stud;

int main()
{
char file[30]; FILE *fp; int f_size;

printf("Enter file name : ");
scanf("%s",file);

fp=fopen(file,"w");


if(fp == NULL)
{
printf("unable to pen file"); exit(0);
}

printf("enter student roll no and name"); scanf("%d %s",&stud.roll_no,stud.s_name);

fprintf(fp,"\nroll no of student : %d \nname of student : %s \n",stud.roll_no,stud.s_name); //fwrite(&stud,sizeof(stud),1,fp);

f_size = fseek(fp,0,SEEK_END); printf("size of file is %d",f_size);

fclose(fp);
printf("records are successfully added");

}

No comments:

Post a Comment