C program help
Geeky1
University of the Pacific (Stockton, CA, USA)
(line) (87) #define maxStudents 45 (88) #define maxColumns 10 (89) #define maxDataPoints 271 (90) (91) void welcome (void); (92) void farewell (void); (93) int getData (int aryStudentData [][maxColumns], int maxDataPoints); (94) int doCalc (int aryStudentData [][maxColumns]); (95) int printData (int aryStudentData [][maxColumns]);
Those are the lines that are relevant; everything above line 87 is comments, except for the include < stdio.h > line. I can post the rest of the source if necessary, but I don't think it is.
The program isn't done, but I'm trying to debug it as I go. Here are the errors Visual C++.NET is giving me. I can't seem to make it happy, and it's driving me nuts.
\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2143: syntax error : missing ')' before 'constant' \Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2143: syntax error : missing '{' before 'constant' \Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2059: syntax error : '<Unknown>' \Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2059: syntax error : ')'
Help, please!! :bawling:
0
Comments
Also, though, after you do that I'd like to know if it works (not just compiles).
I think you might be given some problems because of aryStudentDate[][maxColumns]
I would just use:
int getData (int aryStudentData[][], int maxDataPoints);
int doCalc (int aryStudentData[][]);
int printData (int aryStudentData[][]);
replacing maxDataPoints with a random name (I just used int a, actually) took care of it. Thanks.
A2J, I tried removing the maxColumns, but the compiler had a fit, and (according to my instructor, anyhow) the second value in a 2d array (the number of columns) has to be defined. So... now I just have to finish writing it and figure out why it thinks aryStudentData is an undeclared identifier...
If you're getting more compiler errors then post more source for us to look at and the exact messages. Is your instructor a "I don't wany any warnings" type of guy? Mine was. I am now, too. Warnings may not be errors, but they might lead to them in the future if not immediately. Best to fix all warnings.
I'm not done with it at the moment, tho. I figured I'd finish it first, because the other errors could just be because the program isn't done, so there are some loose ends if you will. To answer your question, yes, my instructor is picky about that kind of stuff. You're right- warnings are going to cause problems later. Right now tho, there are no warnings. Just errors.
I have Jury Duty in the morning (how fun) so I doubt I'll be able to see any questions you might have before tomorrow afternoon, but I'm sure others can help if I'm not available.
The compiler doesn't have any problems with #define X 1 and int X = 1;
The reason is the preprocessor actually replaces "X" in the code with "1" so the compiler will never see "X" it will see "1" and it's that which confuses the compiler.
The compiler never saw "maxDataPoints" it only saw "271" and it wasn't expecting that.
Aaaaaaaaanywho, I figured it was easier to start over after I realized that there's a very similar program in the book. I simply scanned it and edited it a bit.
I've got it almost finished. It's giving me two errors tho:
I'll attach the source code and the build log, but I've never understood these "too many arguments for call through..." errors, and this particular code is straight out of the text, so I don't understand why it's blowing up.
Regardless, there's the error, the code and the buildlog are zipped.
I'll look @ the code and see if I can find what the deal is.
Only error I get is when I run the program:
C:\Documents and Settings\Administrator\Desktop\Lab3>bg_lab_3.exe
LAB 3 - Two-Dimensional Arrays
Error opening file
I use Dev-C++. 4.9.8.0 and then I applied the 4.9.8.7 upgrade to the install directory. You can find it at http://www.bloodshed.net
I put the scores.txt file, the updated source and the exe in another zip file (attached)... I also have to set it up so that the program recognizes the first entry in the text file as the number of students in the class. I think I have an idea of how to do it, but I'm not sure. I was going to put a fscanf line in front of the for loops in the getdata function, and set it = to a variable that the for loop uses to determine the number of rows in the array.
Also, getData() has nested for()s which is fine, but your scanf() is outside the inner for() meaning the dataIn is never changed until the the for()s are completely done unrolling they start all over because of the while(), so only until the while() is reached again (after 46 * 6 iterations) is the dataIn variable assigned a new value.
Also, you're not reading the first line as the # of students and you're not taking the first column as the student ID. I'm working on it, though, but I'm doing other studd too so it might be faster if you just fix it yourself. If you don't post that you've fixed it by the time I'm done then I'll post what I've changed and hopefully it will work for you.
2) I replaced almost all instances of MAX_COLS with (MAX_COLS - 1)
Seems to be working.
I'm working on the other two right now.
But if you want to do it w/ pointers:
int* actualRows;
Then, you guessed it, pass "actualRows" =)
Your arrays are really pointers. C/C++ doesn't have arrays, it only has array-notation. It's all pointers. You're already passing pointers, but you're doing it using array notation. Just change notation, or you could (never tried it before) pass an array of 1 int. eg:
int actualRows[1];
Then pass it like you already are. I don't know of any reason that it wouldn't work, though I have never tried a 1-dimensional 1-element array before that I can recall.
Anyhow, here's the program code (I'll also zip and attach it):
It compiles fine, (albiet with warnings, which you can see below), but when it gets to scanning numbers into the array, it crashes.
Here are the warnings:
Better fix that. None that wimpy array[x] crap here!
I'll try to remember to look @ the code before I go to sleep, but I'll probably be going to sleep in about an hour or so so don't hold your breath thinking I'll get it done tonight.
Read my comments because you made numerous errors. Nothing that isn't uncommon, especially for beginning C students but still pitfalls you need to watch for.
You'll notice I got rid of all of the array stuff and replaced it with (array + i).