Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > please help

Reply
Thread Tools

please help

 
 
JC
Guest
Posts: n/a
 
      08-15-2003
dear all,

i have a program on hand. but i don't know how to handle the header file and
how to get the data.

there are three header file
the first one is Globals.h
#ifndef _GLOBALS_H_
#define _GLOBALS_H_

#include "student.h"
#include "enrolments.h"

StudentDatabase sdatabase;
int student_record_count;
EnrolmentDatabase edatabase;
int enrolment_record_count;

#endif

The second one is student.h
#ifndef _STUDENT_H_
#define _STUDENT_H_

typedef struct StudentData {
char PADDING_1[3];
char STUDENT_NUMBER[10];
char STUDENT_LAST_NAME[15];
char STUDENT_FIRST_NAME[11];
} RECORD;

typedef RECORD StudentDatabase[100];
#endif

the third one is enrolments.h
#ifndef _ENROLMENTS_H_
#define _ENROLMENTS_H_

#include "student.h"

typedef struct EnrolmentData {
char ENR_STUDENT_NUMBER[10];
char ENR_COURSE_NUMBER[5];
char ENR_COURSE_DESCRIPTION[26];
} ENROLMENT_RECORD;

typedef ENROLMENT_RECORD EnrolmentDatabase[100];

#endif

there are three mainly .c file to handle the process.
the main.c is like following
#include <stdio.h>
#include <stdlib.h>

#include "enrolments.h"
#include "student.h"

int main(void) {
printf("1 - Enrolments Management\n");
printf("2 - Students Management\n");
printf("\nPlease enter an option (1,2) and press <ENTER>: ");
scanf("%d", &response);

if response is 1 than call enrolments.c

else
response is 2 than call students.c

}end

in student.c
#include "student.h"
#include "globals.h"


in enrolments.c
#include "enrolments.h"
#include "globals.h"
......
void printStudent() {
extern StudentDatabase sdatabase;
extern int student_record_count;
extern EnrolmentDatabase edatabase;
extern int enrolment_record_count;

printf(" ID Number: %s\n", sdatabase[10].STUDENT_NUMBER ); <<<<<<<<<
what wrong with it.. why i cann't call any data back from student file row
10 ????
printf(" First Name: %s\n", sdatabase[10].STUDENT_FIRST_NAME);
printf(" Surname: %s\n", sdatabase[10].STUDENT_LAST_NAME);

}


Thanks

hope there are someone can tell me why.

JC


 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-15-2003
On Fri, 15 Aug 2003 15:17:15 +0800, "JC" <(E-Mail Removed)> wrote:

>dear all,
>
>i have a program on hand. but i don't know how to handle the header file and
>how to get the data.
>
>there are three header file
>the first one is Globals.h
>#ifndef _GLOBALS_H_
>#define _GLOBALS_H_
>
>#include "student.h"
>#include "enrolments.h"
>
>StudentDatabase sdatabase;
>int student_record_count;
>EnrolmentDatabase edatabase;
>int enrolment_record_count;


At your level, _never_ use global variables.

If you simply refrain from that then 90% of your coding problems
will disappear.

Btw., note that in _C++_ any identifier that begins with an underscore
followed by an uppercase letter is reserved for the implementation, and
yields undefined behavior when used otherwise; I suspect the same is
true for C.


>#endif
>
>The second one is student.h
>#ifndef _STUDENT_H_


So this is most probably incorrect.


>#define _STUDENT_H_
>
>typedef struct StudentData {
> char PADDING_1[3];


_Never_ use all uppercase except for macros.

If this structure definition is provided by your teacher, as
seems very likely (you would probably not come up with the idea
of a padding field), then scald him or her.

Both for all uppercase names and for the padding field.



> char STUDENT_NUMBER[10];
> char STUDENT_LAST_NAME[15];
> char STUDENT_FIRST_NAME[11];
> } RECORD;
>
>typedef RECORD StudentDatabase[100];
>#endif
>
>the third one is enrolments.h
>#ifndef _ENROLMENTS_H_
>#define _ENROLMENTS_H_
>
>#include "student.h"
>
>typedef struct EnrolmentData {
> char ENR_STUDENT_NUMBER[10];
> char ENR_COURSE_NUMBER[5];
> char ENR_COURSE_DESCRIPTION[26];
>} ENROLMENT_RECORD;
>
>typedef ENROLMENT_RECORD EnrolmentDatabase[100];
>
>#endif
>
>there are three mainly .c file to handle the process.
>the main.c is like following
>#include <stdio.h>
>#include <stdlib.h>
>
>#include "enrolments.h"
>#include "student.h"
>
>int main(void) {
>printf("1 - Enrolments Management\n");
> printf("2 - Students Management\n");
> printf("\nPlease enter an option (1,2) and press <ENTER>: ");
> scanf("%d", &response);


No definition of 'response'.


>
>if response is 1 than call enrolments.c


This does not compile.


>
>else
>response is 2 than call students.c


This does not compile.

>
>}end


This does not compile.



>in student.c
>#include "student.h"
>#include "globals.h"
>
>
>in enrolments.c
>#include "enrolments.h"
>#include "globals.h"
>.....
>void printStudent() {
> extern StudentDatabase sdatabase;
> extern int student_record_count;
> extern EnrolmentDatabase edatabase;
> extern int enrolment_record_count;


You already have these declarations in a header file.



>printf(" ID Number: %s\n", sdatabase[10].STUDENT_NUMBER ); <<<<<<<<<
>what wrong with it.. why i cann't call any data back from student file row
>10 ????


You have not provided enough information to answer that.



> printf(" First Name: %s\n", sdatabase[10].STUDENT_FIRST_NAME);
> printf(" Surname: %s\n", sdatabase[10].STUDENT_LAST_NAME);
>
>}



 
Reply With Quote
 
 
 
 
Randy Howard
Guest
Posts: n/a
 
      08-15-2003
In article <(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> >typedef struct StudentData {
> > char PADDING_1[3];

>
> _Never_ use all uppercase except for macros.
>
> If this structure definition is provided by your teacher, as
> seems very likely (you would probably not come up with the idea
> of a padding field), then scald him or her.


Scalding the teacher will probably get you expelled from school,
and perhaps even arrested.

Scolding the teacher will probably get you an F, particularly
if you do so in front of the class.

 
Reply With Quote
 
Binary
Guest
Posts: n/a
 
      08-15-2003
"Alf P. Steinbach" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| Btw., note that in _C++_ any identifier that begins with an underscore
| followed by an uppercase letter is reserved for the implementation, and
| yields undefined behavior when used otherwise; I suspect the same is
| true for C.

Really? Does this have something to do with name mangling? I have been using
the _UPPERCASE for headers =O


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-15-2003
On Fri, 15 Aug 2003 03:15:33 -0500, Randy Howard <(E-Mail Removed)> wrote:

>In article <(E-Mail Removed)>, (E-Mail Removed) says...
>> >typedef struct StudentData {
>> > char PADDING_1[3];

>>
>> _Never_ use all uppercase except for macros.
>>
>> If this structure definition is provided by your teacher, as
>> seems very likely (you would probably not come up with the idea
>> of a padding field), then scald him or her.

>
>Scalding the teacher will probably get you expelled from school,
>and perhaps even arrested.


Aha! So _that_'s what I did wrong...

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-15-2003
On Fri, 15 Aug 2003 08:18:17 GMT, "Binary" <(E-Mail Removed)> wrote:

>"Alf P. Steinbach" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>| Btw., note that in _C++_ any identifier that begins with an underscore
>| followed by an uppercase letter is reserved for the implementation, and
>| yields undefined behavior when used otherwise; I suspect the same is
>| true for C.
>
>Really? Does this have something to do with name mangling?


Nope, it's in order to provide the (compiler & runtime library)
implementor with a guaranteed non-conflicting set of names; it's
defined by the standard.


>I have been using the _UPPERCASE for headers =O


Might work, might not. In _C++_ that's undefined behavior.
Probably so in C also (does anyone know: leading underscore
followed by uppercase?).

 
Reply With Quote
 
JC
Guest
Posts: n/a
 
      08-15-2003
Thanks for help!..

But the problem i met here is. i cann't find any useful information or more
detail about how the header file working and the extern sdatabase or extern
edatabase. and that cann't get the or access all the information from the
student or enrolment class file. Student class file only can handle the data
write or read from the student.dat and Enrolments class file only can handle
the data write or read from the enrolments.dat.

thanks

JC
"JC" <(E-Mail Removed)> wrote in message news:bhi1e9$(E-Mail Removed)...
> dear all,
>
> i have a program on hand. but i don't know how to handle the header file

and
> how to get the data.
>
> there are three header file
> the first one is Globals.h
> #ifndef _GLOBALS_H_
> #define _GLOBALS_H_
>
> #include "student.h"
> #include "enrolments.h"
>
> StudentDatabase sdatabase;
> int student_record_count;
> EnrolmentDatabase edatabase;
> int enrolment_record_count;
>
> #endif
>
> The second one is student.h
> #ifndef _STUDENT_H_
> #define _STUDENT_H_
>
> typedef struct StudentData {
> char PADDING_1[3];
> char STUDENT_NUMBER[10];
> char STUDENT_LAST_NAME[15];
> char STUDENT_FIRST_NAME[11];
> } RECORD;
>
> typedef RECORD StudentDatabase[100];
> #endif
>
> the third one is enrolments.h
> #ifndef _ENROLMENTS_H_
> #define _ENROLMENTS_H_
>
> #include "student.h"
>
> typedef struct EnrolmentData {
> char ENR_STUDENT_NUMBER[10];
> char ENR_COURSE_NUMBER[5];
> char ENR_COURSE_DESCRIPTION[26];
> } ENROLMENT_RECORD;
>
> typedef ENROLMENT_RECORD EnrolmentDatabase[100];
>
> #endif
>
> there are three mainly .c file to handle the process.
> the main.c is like following
> #include <stdio.h>
> #include <stdlib.h>
>
> #include "enrolments.h"
> #include "student.h"
>
> int main(void) {
> printf("1 - Enrolments Management\n");
> printf("2 - Students Management\n");
> printf("\nPlease enter an option (1,2) and press <ENTER>: ");
> scanf("%d", &response);
>
> if response is 1 than call enrolments.c
>
> else
> response is 2 than call students.c
>
> }end
>
> in student.c
> #include "student.h"
> #include "globals.h"
>
>
> in enrolments.c
> #include "enrolments.h"
> #include "globals.h"
> .....
> void printStudent() {
> extern StudentDatabase sdatabase;
> extern int student_record_count;
> extern EnrolmentDatabase edatabase;
> extern int enrolment_record_count;
>
> printf(" ID Number: %s\n", sdatabase[10].STUDENT_NUMBER );

<<<<<<<<<
> what wrong with it.. why i cann't call any data back from student file row
> 10 ????
> printf(" First Name: %s\n", sdatabase[10].STUDENT_FIRST_NAME);
> printf(" Surname: %s\n", sdatabase[10].STUDENT_LAST_NAME);
>
> }
>
>
> Thanks
>
> hope there are someone can tell me why.
>
> JC
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
Console profile for Windows app in VC++ - PLEASE PLEASE PLEASE HELP! MuZZy C++ 7 01-07-2005 08:40 PM
Computer problems please please please help Nick Computer Support 0 06-04-2004 08:49 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments