| | |
student grading system
![]() |
Ok, this looks a bit more sensible. So as you can see that you don’t have to read anything from the first two lines of the file. You really need to extract the information from the third line.
Follow the steps given bellow:
1. Open the file
2. Read the first 2 lines and discard
3. Start buffering the data from thrid line onward and start extracting the data from the buffer using fscanf or the (fgets + sscanf).
4. And store then in a data structure.
If you can get to this point, I will give more instructions! By the way the code you have posted has a very horrible indentation. I refused to look at it. Indent the code and repost it back again.
-ssharish
Follow the steps given bellow:
1. Open the file
2. Read the first 2 lines and discard
3. Start buffering the data from thrid line onward and start extracting the data from the buffer using fscanf or the (fgets + sscanf).
4. And store then in a data structure.
If you can get to this point, I will give more instructions! By the way the code you have posted has a very horrible indentation. I refused to look at it. Indent the code and repost it back again.
-ssharish
Last edited by ssharish2005; Mar 23rd, 2009 at 7:25 pm.
"Any fool can know, point is to understand"
•
•
Join Date: Feb 2009
Posts: 71
Reputation:
Solved Threads: 9
Here's how it works: It enters the first while loop, reads the first line, stores it in the "line" array, then makes x=1, then it does "nothing" because of the so it enters the first while loop again, reads the next line, stores it in the "line" array, makes x = 2, then
OK, it works, but it's very clumsy. First, the
The real issue is that there is no reason to be storing that "junk" at all (except that fgets requires a buffer to store what it reads). Here's a much nicer way to read and ignore those 2 lines:
After that goes your code to read and print the read data, with no extra variable "x", no "line" array, no if statements, etc.
One more thing: you should use "int", not "void" as the return type of your main function. I guess you are using Turbo C++ or some other very old compiler which doesn't insist on that, but int is the standard so you should get in the habit of using it. In other words, write
By the way, you omitted brackets for your second while loop. Also, I have to agree with ssharish2005 that your indentation needs work. But I'll give you a break this time. Here's how your program should look:
C Syntax (Toggle Plain Text)
if( x == 1 ) { //nothing in here }
(x==1) is false so it executes your code in the "else" block.OK, it works, but it's very clumsy. First, the
line[100][100] is an error. There's no reason at all for a 100 x 100 array, and it's actually the wrong type to give as an argument to fgets. Your compiler should be giving you a warning about that. line[100] would be better, but still not so good.The real issue is that there is no reason to be storing that "junk" at all (except that fgets requires a buffer to store what it reads). Here's a much nicer way to read and ignore those 2 lines:
C Syntax (Toggle Plain Text)
for( i = 0; i < 2; i++ ) { while( fgetc(infile) != '\n' ) ; }
One more thing: you should use "int", not "void" as the return type of your main function. I guess you are using Turbo C++ or some other very old compiler which doesn't insist on that, but int is the standard so you should get in the habit of using it. In other words, write
int main() or int main(void) , and then put return 0; as the last line of your program.By the way, you omitted brackets for your second while loop. Also, I have to agree with ssharish2005 that your indentation needs work. But I'll give you a break this time. Here's how your program should look:
C Syntax (Toggle Plain Text)
#include <stdio.h> int main (void) { char matrix[20][200]; int i, j, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20], final[20]; FILE *infile; infile = fopen("studentsmark.txt","r"); for( i = 0; i < 2; i++ ) { while( fgetc(infile) != '\n' ) ; } i=0; while( fscanf(infile,"%d %s %d %d %d %d %d %d",&no[i],matrix[i], &quiz_1[i], &quiz_2[i], &quiz_3[i], &project[i], &midT[i], &final[i]) !=EOF) { printf("%d %s %d %d %d %d %d %d\n",no[i], matrix[i], quiz_1[i], quiz_2[i], quiz_3[i], project[i], midT[i], final[i]); i++; } fclose(infile); return 0; }
![]() |
Similar Threads
- How do I make vectors of an already vectorized thing? (C++)
- e-learning (PHP)
- Help/tips needed to create a software that grade students marks (C++)
- please help me debugg this program (grading System) (C++)
- Intro to Java help (Java)
- Help with an Array GRading assignment (Java)
- C++ program that will Manipulate exam results! (C++)
- Old School Compiler vs New Compiler (C++)
Other Threads in the C Forum
- Previous Thread: Alien numbers problem
- Next Thread: execute some code just before stopping program using CTRL-C
| Thread Tools | Search this Thread |
#include * adobe ansi array asterisks bash binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi





