Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
Add note
Save to My Library
Sync to mobile
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Data Structures With C Lab

Data Structures With C Lab



|Views: 922|Likes:
Published by Pradeep Gowda
Data Structures With C Lab
Data Structures With C Lab

More info:

categoriesTypes, Reviews, Book
Published by: Pradeep Gowda on Jul 22, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, DOC, TXT or read online from Scribd
See More
See less





Data Structures Laboratory Manual 2010-2011/*1.Write a C Program to create a sequential file with atleast 5 records, each record having thestructure shown below: USN - Positive number : Name - 25 Char : Marks1,marks 2,marks 3 are positive NumbersWrite necessary functionsa. To display all the records in the file. b. To search for a specific record based on the USN. In case the record is not found, suitablemessage should be displayed.Both the options in this case must be demonstrated.*/#include<stdio.h>#include<conio.h>typedef struct st{int USN,M1,M2,M3;char Name[25];}record;record stu;void read_data(FILE *fp){ printf("\nEnter the USN\t");scanf("%d",&stu.USN); printf("Enter the Name\t");scanf("%s",&stu.Name); printf("Enter the Marks 1\t");scanf("%d",&stu.M1); printf("Enter the Marks 2\t");scanf("%d",&stu.M2); printf("Enter the Marks 3\t");scanf("%d",&stu.M3);fprintf(fp,"%d\t%s\t%d\t%d\t%d\n",stu.USN,stu.Name,stu.M1,stu.M2,stu.M3);fclose(fp);}void disp_data(record st){ printf("%d%18s\t%5d\t%5d\t%5d\n",st.USN,st.Name,st.M1,st.M2,st.M3);}void main(){FILE *fp;int i,j,n,ch,key,flag=1,found=0;clrscr(); printf("\n Enter the Number of students details\t");scanf("%d",&n);Department of CSE/ISE Page No 1 SIRMVIT
Data Structures Laboratory Manual 2010-2011if(n>0)fp=fopen("student.dat","w"); printf("\n Enter the students Details\n");for(i=0;i<n;i++){ printf("\n Enter the Details of %d Student",i+1);read_data(fp);}fclose(fp);while(flag){clrscr(); printf("\n1 Add Record\n2 Search\n3 Display all\n4 Exit\n Enter the choice\t");scanf("%d",&ch);switch(ch){case 1: fp=fopen("student.dat","a");read_data(fp); break;case 3:fp=fopen("student.dat","r"); printf("\nUSN\t\tName\tMarks 1\tMarks 2\tMarks3\n");while(1){fscanf(fp,"%d%s%d%d%d",&stu.USN,stu.Name,&stu.M1,&stu.M2,&stu.M3);if(feof(fp)) break;disp_data(stu);}fclose(fp); break;case 2:fp=fopen("student.dat","r"); printf("\n Enter the USN Number to search\t");scanf("%d",&key);while(!feof(fp)){fscanf(fp,"%d%s%d%d%d",&stu.USN,stu.Name,&stu.M1,&stu.M2,&stu.M3);if(feof(fp)) break;if(stu.USN==key){ printf("\n Record Found\n");Department of CSE/ISE Page No 2 SIRMVIT
Data Structures Laboratory Manual 2010-2011 printf("\nUSN\t\tName\tMarks1\tMarks 2\tMarks 3\n");disp_data(stu);found=1;}}fclose(fp);if(found==0){ printf("\nThe record with USN %d is notfound\n",key);found=0;} break;case 4:default: flag=0;}getch();}}Department of CSE/ISE Page No 3 SIRMVIT

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->