Thread: Re: [Dev-C++] newbie function_struct_array problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <wa...@wa...> - 2004-05-14 22:24:13
|
On 14 May 2004 at 15:31, Dane Ensign wrote: > Hi, > Dane here. Im having trouble getting my assignment program to compile. > There is something incorrect between the function prototype, function > call, and function headerline. But I cant figure it out. Please can > someone help me to understand where I am going wrong? 1. Don't use ".h" files in a C++ program. Change those to cstdlib and cstring. Assuming, of course, that you really want to use C strings. 2. Your prototype for CreateEmployee needs to be after you define what a "struct Emp" is so that you can put "struct Emp" in your parameter list. 3. Your parameter list needs a pointer to a "struct Emp" not just a "struct []". 4. You're not setting the employee id based on the subscript into the array. 5. You're setting the employee id to 0 for all employees. There are probably other things that I'm not seeing in a cursory glance. I made these mods and the code ran correctly. > > Thank you in advance for any help you can offer me. Im sorry if Im not > supposed to include my code. SHould I attach it next time? It would be really hard to determine what your problems were without the code to look at. :) Watson (the pencil neck) Davis |
|
From: Amit K. S. <ams...@qu...> - 2004-05-15 16:08:33
|
Give the correct type of the first parameter in following function.
void CreateEmployee (struct Emp[], int); //prototype
And you cann't pass the non const value to size of array.
thanks.
-amit
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Dane Ensign
Sent: Saturday, May 15, 2004 3:01 AM
To: dev...@li...
Subject: [Dev-C++] newbie function_struct_array problem
Hi,
Dane here. Im having trouble getting my assignment program to compile. There
is something incorrect between the
function prototype, function call, and function headerline. But I cant
figure it out. Please can someone help me to understand
where I am going wrong?
Thank you in advance for any help you can offer me. Im sorry if Im not
supposed to include my code. SHould I attach it next time?
Here is my source:
______________________________________________
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
void CreateEmployee (struct [], int); //prototype
struct Emp
{
char fname[20];
char lname[20];
int age, id;
};
int qty;
int main()
{
cout << "How many Employees do you want?" << endl;
cin >> qty;
cout << "You chose to create " << qty << "employees" << endl;
Emp Employee[qty];
CreateEmployee(Employee, qty);
//DisplayTeam(qty);
cout << "Nice Job Chap! Peaceout";
system("PAUSE");
return 0;
}
void CreateEmployee(struct Employee[], int qty)
{
int b, qtyLocal;
qtyLocal = qty;
for (b = 0; b < qtyLocal; b++)
{
Employee.id = 0;
cout << "Employee Form" << endl;
cout << "First name: " << endl;
cin >> Employee[b].fname;
cout << "Last name: " << endl;
cin >> Employee[b].lname;
cout << "Age: " << endl;
cin >> Employee[b].age;
cout << "Your Employee Summary is: " << endl;
cout << Employee[b].id << endl << Employee[b].fname << endl <<
Employee[b].lname << endl << Employee[b].age;
}
}
_______________________________________________
|
|
From: Stanley <sms...@iw...> - 2004-05-16 23:50:26
|
> --- On Fri 05/14, Dane Ensign < DE...@pa... > wrote: > From: Dane Ensign [mailto: DE...@pa...] > Subject: [Dev-C++] newbie function_struct_array problem > <skip> > Im having trouble getting my assignment program to compile. There > is something incorrect between the function prototype, > function call, and function headerline. But I cant figure it out. > <skip> > void CreateEmployee (struct [], int); //prototype That line should be: void CreateEmployee( struct Employee[], int); //prototype A struct keyword by itself doesn't mean anything to the compiler. You have to follow it with an already defined struct name. Another problem is that you use the name struct Employee in your function, but you never define a struct Employee. You define a struct Emp, perhaps that should be struct Employee? Also, you'll need to move the definition of the struct before the definition of the prototype in order for the prototype to work. Some rules of thumb: Your prototype and function definition should be nearly identical. Usual order of program files: #include's constant defintions (#defin or const) Structure declarations/typedefs Function prototypes Code Hope this helps. Stanley _______________________________________________ |
|
From: John D A. L. S. I. <joh...@le...> - 2004-05-17 16:32:28
|
might benefit the group. thanks guys Regards John. John D Allen. CEO & President. Leveridge Systems INC. -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of Stanley Sent: Sunday, May 16, 2004 3:50 PM To: DE...@pa...; dev...@li... Subject: RE: [Dev-C++] newbie function_struct_array problem > --- On Fri 05/14, Dane Ensign < DE...@pa... > wrote: > From: Dane Ensign [mailto: DE...@pa...] > Subject: [Dev-C++] newbie function_struct_array problem > <skip> > Im having trouble getting my assignment program to compile. There > is something incorrect between the function prototype, > function call, and function headerline. But I cant figure it out. > <skip> > void CreateEmployee (struct [], int); //prototype That line should be: void CreateEmployee( struct Employee[], int); //prototype A struct keyword by itself doesn't mean anything to the compiler. You have to follow it with an already defined struct name. Another problem is that you use the name struct Employee in your function, but you never define a struct Employee. You define a struct Emp, perhaps that should be struct Employee? Also, you'll need to move the definition of the struct before the definition of the prototype in order for the prototype to work. Some rules of thumb: Your prototype and function definition should be nearly identical. Usual order of program files: #include's constant defintions (#defin or const) Structure declarations/typedefs Function prototypes Code Hope this helps. Stanley _______________________________________________ ------------------------------------------------------- This SF.Net email is sponsored by: SourceForge.net Broadband Sign-up now for SourceForge Broadband and get the fastest 6.0/768 connection for only $19.95/mo for the first 3 months! http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |