943,910 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 2907
  • C RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Jul 21st, 2008
0

Re: urgent: modify code please

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.
Reputation Points: 416
Solved Threads: 181
Nearly a Posting Virtuoso
Adak is offline Offline
1,463 posts
since Jun 2008
Jul 21st, 2008
0

Re: urgent: modify code please

>>>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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008
Jul 22nd, 2008
0

Re: urgent: modify code please

  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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008
Jul 22nd, 2008
0

Re: urgent: modify code please

Click to Expand / Collapse  Quote originally posted by raja289 ...
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);
}
Reputation Points: 1105
Solved Threads: 389
Posting Virtuoso
mitrmkar is offline Offline
1,714 posts
since Nov 2007
Jul 22nd, 2008
0

Re: urgent: modify code please

  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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008
Jul 22nd, 2008
0

Re: urgent: modify code please

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Jul 22nd, 2008
0

Re: urgent: modify code please

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008
Jul 22nd, 2008
0

Re: urgent: modify code please

Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008
Jul 22nd, 2008
0

Re: urgent: modify code please

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008
Jul 22nd, 2008
0

Re: urgent: modify code please

>>>>>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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
raja289 is offline Offline
54 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: two letters = one number?
Next Thread in C Forum Timeline: please help with this question.....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC