in that i have to take 10 students and store their data in FILES then we can search their detail like first name last name roll no etc by structures . use switch statement to search the student by first name . and beside this we can enter or delete a student
Programming & Design - 5 Answers
Random Answers, Critics, Comments, Opinions :
1
What's the question?
2
Do you expect somebody to actually write the entire code for you ? Please specify your exact problem.
3
Well you should read up about file handling in C as for the struct it is an abstract data type so you cna define it to do anything - as you are needing the data of 10 students you can use an array, a linked list would be better but I suspect that your programming skill would not be up for it though it would help with deleting. So here is a rough and ready idea of what you need to do try this code to start with and then improve on it #include<stdio.h> #include<stdlib.h> #include<math.h> int age (int date, int month, int year); int main (void) { FILE *infile, *outfile1, *outfile2; /* Try and make this a struct */ int recno, birthdate, birthmonth, birthyear, ageyears; char sex; if ((infile=fopen("students.txt","r")) == NULL) { printf("Error: input file students.txt cannot be opened"); system("pause"); return 1; } if ((outfile1=fopen("M.txt","w")) == NULL) { printf("Error: output file M.txt cannot be opened"); system("pause"); return 1; } if ((outfile2=fopen("F.dat","w")) == NULL) { printf("Error: output file F.dat cannot be opened"); system("pause"); return 1; } while ( fscanf(infile, "%d %*s %c %d %d %d", &recno, &sex, &birthdate, &birthmonth, &birthyear) > 0 ) { ageyears = age ( birthdate, birthmonth, birthyear ); if ( sex == 'M' ) fprintf ( outfile1, "%-8d%2d\n", recno, ageyears ); else if (sex == 'F' ) fprintf ( outfile2, "%-8d%2d\n", recno, ageyears ); }; fclose(infile); fclose(outfile1); fclose(outfile2); system("pause"); return 0; } int age (int date, int month, int year) { int startdate = 1; int startmonth = 11; int startyear = 2005; int ageinyears; ageinyears = startyear - year; if (month > startmonth || (month == startmonth && date > startdate)) ageinyears--; return ageinyears; }
4
Hi Pinky What exactly your are looking for. I do not think so MA need any project in C programing. Any way i am usiing this free online project management software . You just need to have internet connection , Jst login and start working on the project. Of couse include your friends in that also. For more info click on http://www.proofhub.com
5
Simple: - define a suitable struct - declare an array of these structs - implement functions for manipulating the array of structs
0 comments:
Post a Comment