| | |
urgent: modify code please
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 79
Reputation:
Solved Threads: 7
I don't want to modify your code. I want you to get smart enough to modify your own code.
If you can write out one record, you can write out a million records, but you can't write out records using incorrect data type specifiers. For instance, date of birth is an array, but you're trying to write it out as an int "%d". That won't work!
Why haven't you checked over these simple errors and fixed them by now? They're very basic, but you haven't done that.
Go through your program and find out specifically what does not work, and ask specific questions about it. If you don't know about something, ask about it, again specifically. We can't read your mind, and have no desire to re-write your code from top to bottom or replace a C programming text book. This is just a forum.
You're going to have to get a lot more actively involved if you want to get this program done right. There are three foundations to programming: Study, Work, and Practice. They will help you, pleading to God will not.
If you can write out one record, you can write out a million records, but you can't write out records using incorrect data type specifiers. For instance, date of birth is an array, but you're trying to write it out as an int "%d". That won't work!
Why haven't you checked over these simple errors and fixed them by now? They're very basic, but you haven't done that.
Go through your program and find out specifically what does not work, and ask specific questions about it. If you don't know about something, ask about it, again specifically. We can't read your mind, and have no desire to re-write your code from top to bottom or replace a C programming text book. This is just a forum.
You're going to have to get a lot more actively involved if you want to get this program done right. There are three foundations to programming: Study, Work, and Practice. They will help you, pleading to God will not.
•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
>>>If you can write out one record, you can write out a million records, but you can't write out records using incorrect data type specifiers. For instance, date of birth is an array, but you're trying to write it out as an int "%d". That won't work!
actually when i get some errors from my program then i modify program to simple things to make program easy to understand.
when i modified my program last time it was giving
DATE OF Birth="*OIW:FWFDW"
so i changed date of birth from string to integer that;s why it was "%d"
anyhow right now i am going to try to make my program done. by reading and creating my own logic
thanks for making me to try it myself instead of asking others to do it
but i will contact again if i got some problem.
Thanks alot for giving ur important Time
actually when i get some errors from my program then i modify program to simple things to make program easy to understand.
when i modified my program last time it was giving
DATE OF Birth="*OIW:FWFDW"
so i changed date of birth from string to integer that;s why it was "%d"
anyhow right now i am going to try to make my program done. by reading and creating my own logic
thanks for making me to try it myself instead of asking others to do it
but i will contact again if i got some problem.
Thanks alot for giving ur important Time
•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
C Syntax (Toggle Plain Text)
#include<stdio.h> #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[10],date_of_birth[30]; /*printf("filename\n"); scanf("%s",filename);*/ 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=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=%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 cann;t promote\n"); fprintf(fp,"Student is failed and cann;t promote\n"); } else continue; fail=0; fclose(fp); } for(k=1;k<=10;k++) { /*printf("Input filename"); scanf("%s",filename);*/ fp=fopen("filename","r"); 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); 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); fclose(fp); } getch(); } float avg(float x) { float a=0.0; a=(x/400)*100; return (a); }
now the only problem with program is that
in last when i open the file to print all records of students on screen it just shows last student records ten time instead of each student .
thanks alot
waiting for reply
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
•
•
•
•
just shows last student records ten time instead of each student .
for(k=1;k<=10;k++)
{
// do this ten times ...
// ask the user for the file name <-> shouldn't you
// open the file before this loop?
scanf("%s",filename);*/
// open the file, start reading from the very beginning
fp=fopen("filename","r");
// grab the information ...
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);
// and display it ...
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);
// now close the file <-> shouldn't you close the file after this loop?
fclose(fp);
}•
•
Join Date: Jul 2008
Posts: 41
Reputation:
Solved Threads: 0
c Syntax (Toggle Plain Text)
#include<stdio.h> #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[10],date_of_birth[30]; /*printf("filename\n"); scanf("%s",filename);*/ 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=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=%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 cann;t promote\n"); fprintf(fp,"Student is failed and cann;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); 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); } fclose(fp); getch(); } float avg(float x) { float a=0.0; a=(x/400)*100; return (a); }

sorry if there is any stupid mistake in code (please let me know)
thanks for helping Thanks alot
Last edited by Ancient Dragon; Jul 22nd, 2008 at 6:19 pm. Reason: add line numbers
line 12: increase the array size of filename to 255 characters so that it can hold the maximum number of characters the operating system allows for a filename.
lines 13 and 14: uncomment those two lines.
line 15: remove the quotes around filename.
line 74: you close the file at the end of the first loop iteration. Move that line down after the }
lines 13 and 14: uncomment those two lines.
line 15: remove the quotes around filename.
line 74: you close the file at the end of the first loop iteration. Move that line down after the }
Last edited by Ancient Dragon; Jul 22nd, 2008 at 6:26 pm.
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






