Quote:
> *WITHOUT* using pointers - The program is supposed to set an array for 52
> weeks (initialized to 0). The user is then asked to enter hours for each
> week. As you can see from the attached code, I am having a tough time
> setting up the structure of the array. When the user quits, the program is
> supposed to print the entire array with all the changes made by the hours
> input.
> #include <stdio.h>
> #include <conio.h>
This is not a standard C header file. And it is of no use to a simple
program like yours.
Quote:
> #include <string.h>
> #define MaxFirstName 20
> #define MaxLastName 20
> #define NumWeek 52
> #define NumHours 80
Hmmm, this "NumHours" defined as 80 does not occur in your assignment
description. What is it supposed to mean ?
Quote:
> struct Employee
> {
> int EmployeeNumber;
> char EmployeeFirstName[MaxFirstName];
> char EmployeeLastName[MaxLastName];
> float EmpHours [NumWeek][NumHours];
The "EmpHours" is a two dismensional array. AFAICS your description
requires only a one dimensional array here. You want to store *one*
number per week. Your 2D array allows entering 80 numbers per week.
I'd say You should change this to:
float EmpHours [NumWeek];
Quote:
> int main(void)
> {
> struct Employee OneEmployee;
> OneEmployee=InitializeEmployee(OneEmployee);
I understand that you have to return "OneEmployee" due to not being
allowed to use pointers. But please understand that using pointers
will make this a bit easier.
Quote:
> OneEmployee=GetWeek(OneEmployee);
> OneEmployee=GetHours(OneEmployee);
These two functions are not included in the code that you have posted.
Quote:
> /*NumHours=InEmployee(EmpHours[NumWeek-1]); */
> /*InEmployee.EmpHours[Incr]=0; */
???
Quote:
> for (Incr=0;Incr<NumWeek;Incr++)
Is this really supposed to be a "for" loop that contains a while loop ?
Instead it looks like source code that good severely damaged by
pasting it into the posting. Please check this.
Quote:
> do
> {
> printf("Enter the week number between 1 and 52 or q to exit: ");
> scanf("%d",&NumWeek);
"NumWeek" is a "#define" macro, it is *not* a variable. It can
not be modified.
Quote:
> printf("Enter the number of hours you worked that week or q to exit: ");
> scanf("%d",&NumHours);
"NumHours" is a "#define" macro, it is *not* a variable. It can
not be modified.
Quote:
> }
> while (NumWeek !='q');
The end of loop condition is dangerously wrong. For one thing, because
"NumWeek" is a macro. But even if "NumWeek" would be a variable, it
would be a number (hopefully a week number) and comparing a number
to a letter will not give you what you want.
And this loop essentially does nothing more than input lots of numbers
that are not used at all. I'd have hoped to see something like:
OneEmployee.EmpHours[weekNumber] = numberOfHours;
Please be aware that "scanf()" is a very dangerous and confusing
function. It looks deceptively easy to use, but is full of deadly
traps and pitfalls and gotchas. Especially when used inside a loop.
"fgets()" look more complicated to use, but will be a lot more
reliable and predictable.
Quote:
> void GetString(char InString[], int Length)
Hah, you are using pointer, without noticing it :-)
BTW, the standard C function "fgets()" does almost exactly what you
do in this function: It reads a line of text from the user. The main
difference is that it includes the "\n" in the string and that you
must specify "stdin" specifically:
/* Read one line and remove trailing '\n' (without using pointers) */
fgets( inString, maxSize, stdin );
length = strlen(inString];
if ( inString[length] == '\n' ) inString[length] = \0';
Quote:
> fflush(stdin);
This is generally *not* a good idea. I've seen that you use this a lot.
But the C standard says that "fflush()" is *not* defined for input
streams. With most compilers it will simply do nothing, with some it
might crash the program.
Using "fgets()" will typicallly work without having to empty the
input buffer.
Quote:
> struct Employee InitializeEmployee(struct Employee InEmployee)
[snip]
Quote:
> for(Incr=0;Incr<NumWeek;Incr++)
Here is another of those empty loops that does not have a loop body.
What is it supposed to do ?
Quote:
> return InEmployee;
> }
[rest of code snipped]
I'd suggest that you have a good look at my comments and do some
serious rewriting of your code. If you can't get it to work, simply
ask again. But please try to be specific about what exactly your
problem is. For instance the above code does not compile at all
and is full of strnage errors. Was this your main problem ? Try
to pay close attention to compiler error messages. If you have some
code and do not understand the error message, you might ask here
about that message specifically.
Stephan
(initiator of the campaign against grumpiness in c.l.c)