| | |
urgent: modify code please
Thread Solved |
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
i think i have to sleep now because i am living in someone else house now a days
but tomorrow i will be here at same time
and at morning time i will check for updates
PLEASE RUN THIS PROGRAM ON UR COMPUTER AND SEE WHAT EXCEPTIONS COME THERE
I AM USING BLOODSHED DEV C++ 4.96 VERSION
THANKS ALOT I REALLY APPREICAITE YOU PEOPLE GIVING ME UR IMPORTANT TIME
but tomorrow i will be here at same time
and at morning time i will check for updates
PLEASE RUN THIS PROGRAM ON UR COMPUTER AND SEE WHAT EXCEPTIONS COME THERE
I AM USING BLOODSHED DEV C++ 4.96 VERSION
THANKS ALOT I REALLY APPREICAITE YOU PEOPLE GIVING ME UR IMPORTANT TIME
•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
c Syntax (Toggle Plain Text)
#include<stdio.h>[LIST=1] #include<string.h> #include<conio.h> #pragma warning(disable: 4996) float avg(float x); main() { FILE *fp; int k,students=10,subjects=4,i,j,id_number,fail; float marks[100],total=0,average; char name[30],course_enrolled[30],filename[255],date_of_birth[30]; printf("filename\n"); scanf("%s",filename); fp=fopen(filename,"w"); for(i=1;i<=2;i++) { printf("Enter Name of Student\n"); fscanf(stdin,"%s",name); fprintf(fp,"%s\n",name); printf("Enter Course In Which Student Is Enrolled\n"); fscanf(stdin,"%s",course_enrolled); fprintf(fp,"%s\n",course_enrolled); printf("Enter Date Of Birth\n"); fscanf(stdin,"%s",date_of_birth); fprintf(fp," %s\n",date_of_birth); printf("Enter ID Number\n"); fscanf(stdin,"%d",&id_number); fprintf(fp," %d\n",id_number); for(j=1;j<=4;j++) { printf("Enter Marks for Subject\n"); scanf("%f",&marks[j]); total=total+marks[j]; if(marks[j]<50) fail=fail+1; else continue; } average=avg(total); total=0.0; printf("AVERAGE=%2f\n",average); fprintf(fp," %2f\n",average); if(average>=70) printf("Grade A\n"); else if(average>=60&&average<70) printf("Grade B\n"); else if(average>=50&&average<60) printf("Grade C\n"); else if(average>=45&&average<50) printf("Grade D\n"); else if(average>=40&&average<45) printf("Grade E\n"); else if(average<40) printf("Fail\n"); else continue; if(fail>=2) printf("Student is failed and cann;t promote\n"); else continue; fail=0; } fclose(fp); printf("Input filename"); scanf("%s",filename); fp=fopen(filename,"r"); for(k=1;k<=2;k++) { fscanf(fp,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s AVERAGE= %2f\n",name,course_enrolled,&id_number,date_of_birth,average); fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s AVERAGE= %2f\n",name,course_enrolled,id_number,date_of_birth,average); } fclose(fp); getch(); } float avg(float x) { float a=0.0; a=(x/400)*100; return (a); }[/LIST]
Last edited by Ancient Dragon; Jul 22nd, 2008 at 7:15 pm. Reason: add line numbers
delete lines 70 and 71 because the program already knows the filename from lines 13 and 14. No point in asking for the filename again.
line 75: fscanf() is mal-formed. Here is correction
line 75: fscanf() is mal-formed. Here is correction
C Syntax (Toggle Plain Text)
while(fscanf(fp,"%s%s%s%d%f", name, course_enrolled, date_of_birth, &id_number, &average) > 0) { fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,average); }
Last edited by Ancient Dragon; Jul 22nd, 2008 at 7:28 pm.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
•
•
Join Date: Jun 2008
Posts: 128
Reputation:
Solved Threads: 9
I believe this will work better. Note that you were writing out the variables in a slightly different order than you were fscanf'ing them back in, and the failing message shouldn't go into the data file, because you have no way of handling it when the data is read back in.
Instead, just add an if statement to your program after the data is read back in from the file, and then print the "student has failed and can't promote" message, onto the screen.
Instead, just add an if statement to your program after the data is read back in from the file, and then print the "student has failed and can't promote" message, onto the screen.
C Syntax (Toggle Plain Text)
#include<stdio.h> #include<string.h> #include<conio.h> #pragma warning(disable: 4996) float avg(float x); int main() { FILE *fp; int k,students=10,subjects=4,i,j,id_number,fail; float marks[100],total=0,average; char name[30],course_enrolled[30],filename[10],date_of_birth[30]; //printf("filename\n"); //scanf("%s",filename); printf("\n\n\n\n"); fp=fopen("filename","w"); for(i=1;i<=10;i++) { printf("Enter Name of Student\n"); fscanf(stdin,"%s",name); fprintf(fp,"%s\n",name); printf("Enter Course In Which Student Is Enrolled\n"); fscanf(stdin,"%s",course_enrolled); fprintf(fp,"%s\n",course_enrolled); printf("Enter Date Of Birth\n"); fscanf(stdin,"%s",date_of_birth); fprintf(fp," %s\n",date_of_birth); printf("Enter ID Number\n"); fscanf(stdin,"%d",&id_number); fprintf(fp," %d\n",id_number); for(j=0;j<4;j++) { printf("Enter Marks for Subject\n"); scanf("%f",&marks[j]); total=total+marks[j]; if(marks[j]<50) fail=fail+1; // else // continue; } average=avg(total); total=0.0; printf("AVERAGE=%f\n",average); fprintf(fp," %f\n",average); if(average>=70) printf("Grade A\n"); else if(average>=60&&average<70) printf("Grade B\n"); else if(average>=50&&average<60) printf("Grade C\n"); else if(average>=45&&average<50) printf("Grade D\n"); else if(average>=40&&average<45) printf("Grade E\n"); else if(average<40) printf("Fail\n"); // else // continue; if(fail>=2) { printf("Student is failed and can't promote\n"); //fprintf(fp,"Student is failed and can't promote\n"); } // else // continue; fail=0; } fclose(fp); fp=fopen("filename","r"); for(k=1;k<=10;k++) { //printf("Input filename"); //scanf("%s",filename); //fscanf(fp,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,&id_number,date_of_birth,average); fscanf(fp,"%s %s %s %d %f",name,course_enrolled,date_of_birth, &id_number,&average); fprintf(stdout,"NAME= %s\tCOURSE= %s\t ID= %d\t DOB= %s\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,average); if(average < 40) printf("\n*This student has failed and can't promote*\n"); } fclose(fp); getch(); return 0; } float avg(float x) { float a=0.0; a=(x/400)*100; return (a); }
Last edited by Adak; Jul 22nd, 2008 at 7:38 pm.
![]() |
Similar Threads
- Urgent help on Applet (Java)
- I am struk up with this problem (ASP.NET)
- Urgent!!!!!!URGENTTTTT! (Python)
- Help me in username and password validation through accessing the database (ASP.NET)
- urgent (Java)
- data grid.... very urgent...... (C#)
- how to read data from database page by page, please it is urgent... (JSP)
- Urgent help needed over here (C++)
- login code in C#(its urgent) (C#)
Other Threads in the C Forum
- Previous Thread: two letters = one number?
- Next Thread: please help with this question.....
Views: 2593 | Replies: 38
| Thread Tools | Search this Thread |
Tag cloud for C
api array arrays binary binarysearch c++ calculate char code coke command conversion convert copyimagefile creafecopyofanytypeoffileinc database decimal dice directory do-not-use drawing dude dumpandrun dynamic error evaluation exec fgets file fork forloop function functions givemetehcodez global grade graphics gray hacking homework i/o incrementoperators input insert int integer lazy leet_speak line linked linkedlist linux list loop malloc matrix memory mysql no-effort number opensource output path pointer pointers power precedence problem process program programming question radix read recursion recursive recv research reverse scanf scripting segmentationfault sequential socketprograming source spoonfeeding string strings strtok structures student system turbo-c unix user variable visual whileloop windows winxp






