please help

J

JC

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
 
A

Alf P. Steinbach

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.

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);

}
 
R

Randy Howard

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.
 
B

Binary

| 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
 
A

Alf P. Steinbach

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...
 
A

Alf P. Steinbach

| 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?).
 
J

JC

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top