urgent: modify code please

Thread Solved

Join Date: Jun 2008
Posts: 79
Reputation: Adak is an unknown quantity at this point 
Solved Threads: 7
Adak Adak is offline Offline
Junior Poster in Training

Re: urgent: modify code please

 
0
  #21
Jul 21st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #22
Jul 21st, 2008
>>>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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #23
Jul 22nd, 2008
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. #pragma warning(disable: 4996)
  5.  
  6. float avg(float x);
  7. main()
  8. {
  9. FILE *fp;
  10. int k,students=10,subjects=4,i,j,id_number,fail;
  11. float marks[100],total=0,average;
  12. char name[30],course_enrolled[30],filename[10],date_of_birth[30];
  13. /*printf("filename\n");
  14.   scanf("%s",filename);*/
  15. fp=fopen("filename","w");
  16. for(i=1;i<=10;i++)
  17. {
  18. printf("Enter Name of Student\n");
  19. fscanf(stdin,"%s",name);
  20. fprintf(fp,"%s\n",name);
  21.  
  22. printf("Enter Course In Which Student Is Enrolled\n");
  23. fscanf(stdin,"%s",course_enrolled);
  24. fprintf(fp,"%s\n",course_enrolled);
  25.  
  26. printf("Enter Date Of Birth\n");
  27. fscanf(stdin,"%s",date_of_birth);
  28. fprintf(fp," %s\n",date_of_birth);
  29.  
  30. printf("Enter ID Number\n");
  31. fscanf(stdin,"%d",&id_number);
  32. fprintf(fp," %d\n",id_number);
  33.  
  34. for(j=1;j<=4;j++)
  35. {
  36. printf("Enter Marks for Subject\n");
  37. scanf("%f",&marks[j]);
  38. total=total+marks[j];
  39. if(marks[j]<50)
  40. fail=fail+1;
  41. else
  42. continue;
  43. }
  44. average=avg(total);
  45. total=0.0;
  46. printf("AVERAGE=%f\n",average);
  47. fprintf(fp," %f\n",average);
  48. if(average>=70)
  49. printf("Grade A\n");
  50. else if(average>=60&&average<70)
  51. printf("Grade B\n");
  52. else if(average>=50&&average<60)
  53. printf("Grade C\n");
  54. else if(average>=45&&average<50)
  55. printf("Grade D\n");
  56. else if(average>=40&&average<45)
  57. printf("Grade E\n");
  58. else if(average<40)
  59. printf("Fail\n");
  60. else
  61. continue;
  62.  
  63.  
  64.  
  65.  
  66. if(fail>=2)
  67. {
  68. printf("Student is failed and cann;t promote\n");
  69. fprintf(fp,"Student is failed and cann;t promote\n");
  70. }
  71. else
  72. continue;
  73. fail=0;
  74. fclose(fp);
  75. }
  76. for(k=1;k<=10;k++)
  77. {
  78. /*printf("Input filename");
  79.   scanf("%s",filename);*/
  80. fp=fopen("filename","r");
  81. 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);
  82. 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);
  83. fclose(fp);
  84. }
  85. getch();
  86. }
  87. float avg(float x)
  88. {
  89. float a=0.0;
  90. a=(x/400)*100;
  91. return (a);
  92. }




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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: urgent: modify code please

 
0
  #24
Jul 22nd, 2008
Originally Posted by raja289 View Post
just shows last student records ten time instead of each student .
Isn't that quite obvious if you take a close look at the loop,

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);
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #25
Jul 22nd, 2008
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. #pragma warning(disable: 4996)
  5.  
  6. float avg(float x);
  7. main()
  8. {
  9. FILE *fp;
  10. int k,students=10,subjects=4,i,j,id_number,fail;
  11. float marks[100],total=0,average;
  12. char name[30],course_enrolled[30],filename[10],date_of_birth[30];
  13. /*printf("filename\n");
  14.   scanf("%s",filename);*/
  15. fp=fopen("filename","w");
  16. for(i=1;i<=10;i++)
  17. {
  18. printf("Enter Name of Student\n");
  19. fscanf(stdin,"%s",name);
  20. fprintf(fp,"%s\n",name);
  21.  
  22. printf("Enter Course In Which Student Is Enrolled\n");
  23. fscanf(stdin,"%s",course_enrolled);
  24. fprintf(fp,"%s\n",course_enrolled);
  25.  
  26. printf("Enter Date Of Birth\n");
  27. fscanf(stdin,"%s",date_of_birth);
  28. fprintf(fp," %s\n",date_of_birth);
  29.  
  30. printf("Enter ID Number\n");
  31. fscanf(stdin,"%d",&id_number);
  32. fprintf(fp," %d\n",id_number);
  33.  
  34. for(j=1;j<=4;j++)
  35. {
  36. printf("Enter Marks for Subject\n");
  37. scanf("%f",&marks[j]);
  38. total=total+marks[j];
  39. if(marks[j]<50)
  40. fail=fail+1;
  41. else
  42. continue;
  43. }
  44. average=avg(total);
  45. total=0.0;
  46. printf("AVERAGE=%f\n",average);
  47. fprintf(fp," %f\n",average);
  48. if(average>=70)
  49. printf("Grade A\n");
  50. else if(average>=60&&average<70)
  51. printf("Grade B\n");
  52. else if(average>=50&&average<60)
  53. printf("Grade C\n");
  54. else if(average>=45&&average<50)
  55. printf("Grade D\n");
  56. else if(average>=40&&average<45)
  57. printf("Grade E\n");
  58. else if(average<40)
  59. printf("Fail\n");
  60. else
  61. continue;
  62.  
  63.  
  64.  
  65.  
  66. if(fail>=2)
  67. {
  68. printf("Student is failed and cann;t promote\n");
  69. fprintf(fp,"Student is failed and cann;t promote\n");
  70. }
  71. else
  72. continue;
  73. fail=0;
  74. fclose(fp);
  75. }
  76. fp=fopen("filename","r");
  77. for(k=1;k<=10;k++)
  78. {
  79. /*printf("Input filename");
  80.   scanf("%s",filename);*/
  81. 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);
  82. 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);
  83. }
  84. fclose(fp);
  85. getch();
  86. }
  87. float avg(float x)
  88. {
  89. float a=0.0;
  90. a=(x/400)*100;
  91. return (a);
  92. }
still same problem !
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: urgent: modify code please

 
0
  #26
Jul 22nd, 2008
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 }
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #27
Jul 22nd, 2008
waiting and if anyone can chat with me on yahoo or msn please tell me i want to slove this code tomorrow i am from london now's it's 10 30 pm here
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #28
Jul 22nd, 2008
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #29
Jul 22nd, 2008
i did but now it displays a a message
"Enter your name"
but when i enter my name then it shows error

final1.c encountered a problem and need to be closed sorry for enconvience
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: urgent: modify code please

 
0
  #30
Jul 22nd, 2008
>>>>>line 15: remove the quotes around filename.
i removed quotes at line 15 and


>>>>line 74: you close the file at the end of the first loop iteration. Move that line down after the }
closed file after first for loop
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC