2
代碼
我試圖創建一個程序來管理一所大學,要做到這一點,我認爲建立一個stuct
學生,並把另一struct
分支它裏面。這是我做了什麼,這都不盡如人意無法訪問的結構membre
base.h
#define DEG_SIZE 2
#define BRANCH_SIZE 5
struct Branch{
char Departement;
char Year;
}b;
typedef struct Branch _BRANCH;
_BRANCH branch[BRANCH_SIZE];
struct Student_informations{
char Stud_name;
float deg[DEG_SIZE];
char* Stud_year;
char Payment_State;
_BRANCH Stud_branch;
}c;
typedef struct Student_informations _STUDENT;
enum Departement
{ MATH,PHY,
CHY,GIO,
BIO,INFO
};
enum Year
{ first,second,
licence,master,
doc
};
enum Payment
{
TRUE,
FALSE
};
student.c
/*<--------------SETUP-------------->*/
/*=============-MATH-=============*/
//SMIA
branch[0].Departement = MATH;
branch[0].Year = first;
//SMI/SMA
branch[1].Departement = MATH;
branch[1].Year = second;
//SMF/SMA
branch[2].Departement = MATH;
branch[2].Year = licence;
//MASTER-MATH
branch[3].Departement = MATH;
branch[3].Year = master;
//DOCTURAT-MATH
branch[4].Departement = MATH;
branch[4].Year = doc;
/*=============-MATH-=============*/
/*<--------------SETUP-------------->*/
#include "base.h"
void set_students(_STUDENT* student)
{
puts("Enter the Full name");
scanf("%s", student->Stud_name);
puts("Enter his deg");
for(int k=0; k < DEG_SIZE; ++k){
printf("deg[%d]", k+1);
scanf("%f",student->deg[k]);
puts("");
}// end for
puts("enter the year");
scanf("%s", student->Stud_year);
Stud_branch -> branch[2];
puts("DONE!");
}// end set_students()
AF.C
#include "base.h"
/*beginning of main()*/
int main(int argc,char *argv[])
{
_STUDENT Student;
set_students(&Student);
return EXIT_SUCCESS;
}//end main()
編譯..
[[email protected] src-new] $ make
gcc -I. -c -o af.o af.c
gcc -I. -c -o student.o student.c
student.c: In function ‘set_students’:
student.c:23:25: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
student->Payment_State = hold;
^
Building the application core..
gcc -o x af.o student.o -I.
Finish.
[[email protected] src-new] $
執行
[[email protected] src-new] $ ./x
10
Enter the Full name
anas
Segmentation fault (core dumped)
[[email protected] src-new] $
我想了兩天來解決這個問題,誰能幫我瞭解問題出在哪裏以及如何解決問題
student.c不完整。特別是,我沒有看到產生警告的代碼行。 – dbush
以'_'和大寫字母開頭的標識符由標準保留。 **不要在應用程序代碼中使用它們。** – Olaf