我正在研究我的学校项目表格数据结构,我遇到类型长的问题.我想设计一个像大学注册系统这样的小项目.首先,如果他想注册或退出,那么他就会选择.如果他想要注册,那么他将输入他的名字和gpa,根据他的gpa选择可用的专业,系统将自动生成一个id.
问题是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; …Run Code Online (Sandbox Code Playgroud) 为什么在scanf()程序中的格式说明符之前使用空格时工作正常呢?代码如下:
printf("What's your username: ");
scanf(" %s", username);
printf("Do you want to make a deposit or a withdrawal? [d/w]\n");
scanf(" %c", &choice);
Run Code Online (Sandbox Code Playgroud)
当我没有像下面这个代码的空格时,它会退出:
printf("What's your username: ");
scanf("%s", username);
printf("Do you want to make a deposit or a withdrawal? [d/w]\n");
scanf("%c", &choice);
Run Code Online (Sandbox Code Playgroud)
对此有一个很好的解释吗?
我观察到为数组分配的内存似乎是动态的.
以下是我在本教程中找到的示例代码:
#include <stdio.h>
main() {
int LA[] = {1,3,5,7,8};
int item = 10, k = 3, n = 5;
int i = 0, j = n;
printf("The original array elements are :\n");
for(i = 0; i<n; i++) {
printf("LA[%d] = %d \n", i, LA[i]);
}
n = n + 1;
while( j >= k){
LA[j+1] = LA[j];
j = j - 1;
}
LA[k] = item;
printf("The array elements after insertion :\n");
for(i = 0; i<n; i++) …Run Code Online (Sandbox Code Playgroud) Pattern.compile("[A-Z0-9._%+-]") 它编译什么???