我正在處理我的學校項目表單數據結構,並且遇到long類型的問題。 我想設計一個像大學註冊系統這樣的小型項目。 首先,如果他想要註冊或退出,他可以選擇。 如果他想註冊,那麼他會輸入他的名字和GPA來選擇基於他的GPA可用的專業,系統會自動生成一個ID。使用long long型打印
問題是id沒有正確遞增。
附加信息: 我使用
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct student{
char name[30];
int GPA;
unsigned long ID;
char colloege[100];
student *next, *prev;
};
student *stu, *cur, *head, *tail;
void insertfront();
void displaylist(){
unsigned long id=214000000;
cur=head;
printf(" ");
if(cur==NULL)
printf(" ");
else
while(cur!=NULL){
printf("Name:%s\t",cur->name);
printf("ID:%d\t",cur->ID=id++);
printf("GPA:%d\t",cur->GPA);
printf("Colloege of:%s\t",cur->colloege);
printf("\n");
cur=cur->next;
}
}
void main(){
clrscr();
int x;
printf("\n\t\t\t\t******* King Faisal University *********\n");
while(x!=2){
printf("\n press 1 to insert your information ,press 2 to exit\n");
scanf("%d",&x);
insertfront();
displaylist();
}
stu=NULL;
cur=NULL;
head=NULL;
tail=NULL;
getch();
}
void insertfront(){
int x,c;
stu=(student*)malloc(sizeof(student));
fflush(stdin);
printf("Enter your name:\n");
scanf("%[^\n]%*c",stu->name);
printf("Enter your GPA:\n");
scanf("%ul",&stu->GPA);
printf("\n Available Colloeges\n");
if(stu->GPA>=85)
{
printf("1.Colloege of Medicine\n 2.Colloege of Engenering\n 3.Colloege of Computer Science\n 4.Colloege of Business\n 5.Colloege of Art\n");
printf("Enter the colloege number \n");
scanf("%d",&c);
switch(c){
case 1: strcpy(stu->colloege,"Medicien");break;
case 2: strcpy(stu->colloege,"Engenering");break;
case 3: strcpy(stu->colloege,"Computer Science");break;
case 4: strcpy(stu->colloege,"Business");break;
case 5: strcpy(stu->colloege,"Art");break;
}
}
else if(stu->GPA>=75)
{
printf("1.Colloege of Computer Science\n 2.Colloege of Business\n 3.Colloege of Art\n");
printf("Enter the colloege number\n");
scanf("%d",&c);
switch(c){
case 1: strcpy(stu->colloege,"Computer Science");break;
case 2: strcpy(stu->colloege,"Business");break;
case 3: strcpy(stu->colloege,"Art");break;
}
}
else
strcpy(stu->colloege,"Art");
if(head==NULL)
{
stu->next=NULL;
stu->prev=NULL;
head=stu;
tail=stu;
}
else
{
stu->next=head;
stu->prev=NULL;
head->prev=stu;
head=stu;
}
}
你能否詳細說明你遇到的問題。你有構建錯誤嗎?運行時錯誤或崩潰?意外的結果?您可能想要[閱讀如何提出好問題](http://stackoverflow.com/help/how-to-ask),以及如何創建[最小,完整和可驗證示例](http:/ /stackoverflow.com/help/mcve)。最後,你應該學會如何格式化你的代碼,使其可讀性和縮進。 –
您使用的是C++編譯器嗎?你的代碼是無效的C(結構名不會自動進入全局範圍C)!爲了您自己的理智,使用C編譯器的C代碼:-) – pmg
在打印時設置記錄ID是純粹的邪惡。 –