| | |
urgent: modify code please
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
http://s3.supload.com/free/lastscan-...3716.jpg/view/
up there is description of code
and here;'s code
up there is description of code
and here;'s code
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<string.h> float avg(float); main() { FILE *p[2]; int k,students=10,subjects=4,i,j,id_number,date_of_birth,fail=0; float marks[100],total=0,avg; char name[30],course_enrolled[30],filename[10]; for(i=1;i<=2;i++) { printf("filename"); scanf("%s",&filename); p[i]=fopen(filename,"w"); printf("Enter Name of Student\n",p[i]); fscanf(stdin,"%s",&name,p[i]); printf("Enter Course In Which Student Is Enrolled\n",p[i]); fscanf(stdin,"%s",&course_enrolled,p[i]); printf("Enter ID Number Of %s Enrolled in Course %s\n",name,course_enrolled,p[i]); fscanf(stdin,"%d",&id_number,p[i]); printf("Enter Date Of Birth Of %s Enrolled in Course %s and\n ID-Number is %d\n",name,course_enrolled,id_number,p[i]); fscanf(stdin,"%d",&date_of_birth,p[i]); for(j=1;j<=4;j++) { printf("Enter Marks for Subject %d for Student %s\n",j,name); fscanf(stdin,"%f",&marks[j]); total=total+marks[j]; if(marks[j]<50) fail=fail+1; else continue; } avg=(total/400)*100; printf("AVERAGE=%f\n",avg); if(avg>=70) printf("Grade A\n"); if(avg>=60&avg<70) printf("Grade B\n"); else if(avg>=50&avg<60) printf("Grade C\n"); else if(avg>=45&avg<50) printf("Grade D\n"); else if(avg>=40&avg<45) printf("Grade E\n"); else if(avg<40) printf("Fail\n"); if(fail>=2) printf("Student is failed and cann;t promote\n"); else continue; fclose (p[i]); } for(k=1;k<=2;k++) { printf("Input filename"); scanf("%s",&filename); p[k]=fopen(filename,"r"); fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %d\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,avg); fclose (p[k]); } getch(); }
Last edited by Ancient Dragon; Jul 10th, 2008 at 6:26 am. Reason: corrected code and img tags
•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
oh sorry for that link !
here;s another link
http://www.MegaShare.com/443191
and the main problem with code is that
when i save data in different files and ask them to fetch the same data from files but it just show me the data of last file no matters if i enter the name of first file
and it is adding average of last student with the current one
and i want to use 1 user defined function here can u tell me which function should i make except average !
here;s another link
http://www.MegaShare.com/443191
and the main problem with code is that
when i save data in different files and ask them to fetch the same data from files but it just show me the data of last file no matters if i enter the name of first file
and it is adding average of last student with the current one
and i want to use 1 user defined function here can u tell me which function should i make except average !
The indentation of your program is terrible -- hopefully it was just a problem with posting here. So here is a corrected copy
When I compiled it using VC++ 2008 Express I got several warnings which you need to correct. NEVER EVER ignore warnings because most of the time they are really errors.
>>test1.c(39) : warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence
That warning message tells you to look at line 39 and check of the & operator is correct. Its not what you want -- you wanted the boolean && operator, not the bitwise & operator. The code has similar problem on other lines.
Another problem: lines 15 and 58: remove the & address operator before filename. Character arrays like filename are always passed by address, and adding the & address operator passes a pointer to a pointer, which is not what you want.
I don't have your input file(s) so I can't run the program to test it out.
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<string.h> #pragma warning(disable: 4996) float avg(float); main() { FILE *p[2]; int k,students=10,subjects=4,i,j,id_number,date_of_birth,fail=0; float marks[100],total=0,avg; char name[30],course_enrolled[30],filename[10]; for(i=1;i<=2;i++) { printf("filename"); scanf("%s",&filename); p[i]=fopen(filename,"w"); printf("Enter Name of Student\n",p[i]); fscanf(stdin,"%s",&name,p[i]); printf("Enter Course In Which Student Is Enrolled\n",p[i]); fscanf(stdin,"%s",&course_enrolled,p[i]); printf("Enter ID Number Of %s Enrolled in Course %s\n",name,course_enrolled,p[i]); fscanf(stdin,"%d",&id_number,p[i]); printf("Enter Date Of Birth Of %s Enrolled in Course %s and\n ID-Number is %d\n",name,course_enrolled,id_number,p[i]); fscanf(stdin,"%d",&date_of_birth,p[i]); for(j=1;j<=4;j++) { printf("Enter Marks for Subject %d for Student %s\n",j,name); fscanf(stdin,"%f",&marks[j]); total=total+marks[j]; if(marks[j]<50) fail=fail+1; else continue; } avg=(total/400)*100; printf("AVERAGE=%f\n",avg); if(avg>=70) printf("Grade A\n"); if(avg>=60&avg<70) printf("Grade B\n"); else if(avg>=50&avg<60) printf("Grade C\n"); else if(avg>=45&avg<50) printf("Grade D\n"); else if(avg>=40&avg<45) printf("Grade E\n"); else if(avg<40) printf("Fail\n"); if(fail>=2) printf("Student is failed and cann;t promote\n"); else continue; fclose (p[i]); } for(k=1;k<=2;k++) { printf("Input filename"); scanf("%s",&filename); p[k]=fopen(filename,"r"); fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %d\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,avg); fclose (p[k]); } getch(); }
When I compiled it using VC++ 2008 Express I got several warnings which you need to correct. NEVER EVER ignore warnings because most of the time they are really errors.
>>test1.c(39) : warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence
That warning message tells you to look at line 39 and check of the & operator is correct. Its not what you want -- you wanted the boolean && operator, not the bitwise & operator. The code has similar problem on other lines.
Another problem: lines 15 and 58: remove the & address operator before filename. Character arrays like filename are always passed by address, and adding the & address operator passes a pointer to a pointer, which is not what you want.
I don't have your input file(s) so I can't run the program to test it out.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
About the files: I see now that your program creates them. Its not necessary to have an array of file pointers, e.g.
You are asking people to enter the birth date as a single integer -- I don't know about you but I like to enter my birthdate in MM/DD/YYYY or MM-DD-YYYY format and you can't do that with your program. Suggest you change the data type of birthdate to a character array so that you can enter it in normal fashion.
FILE *p[2]; . All you need is one and just reuse it. FILE* p; You are asking people to enter the birth date as a single integer -- I don't know about you but I like to enter my birthdate in MM/DD/YYYY or MM-DD-YYYY format and you can't do that with your program. Suggest you change the data type of birthdate to a character array so that you can enter it in normal fashion.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
>>when i save data in different files and ask them to fetch the same data from files but it just show me the data of last file no matters if i enter the name of first file
You have to add some more code to read the file after it is opened on line 62. Your program opens the file then just ignores it.
>>and it is adding average of last student with the current one
You have to reinitialize total to 0 before starting the loop on line 25.
You have to add some more code to read the file after it is opened on line 62. Your program opens the file then just ignores it.
>>and it is adding average of last student with the current one
You have to reinitialize total to 0 before starting the loop on line 25.
Last edited by Ancient Dragon; Jul 10th, 2008 at 7:20 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Actually, now that I look at your program closer, your program doesn't write anything to those files. In post #5 above, the program opens the file on line 16 and closes it on line 53, never writes anything to it inbetween those two lines. So, somewhere before line 53 you have to add code to write the data to the file. What to write? Look at line 60 -- you have to write those entries (name, course title, id number, dob, and average) to the file. Then after line 59 you have to insert another line or so that reads those same variables from the file. Use fscanf() or fgets() to do that.
[icode]
[icode]
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
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.....
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






