案例3是问题区域,整数数组正在运行,它很好,但是"第一个"和"最后"字符串数组根本不起作用。我不知道如何解决它。
我必须只使用stdio.h和stdlib.h库。" first"和"最后"是2d char指针,我喜欢20个元素,最多30个字符。添加和编辑都很好,但是"首先[temp] =第一个[temp + 1];& #34;当我尝试" strcpy(first [temp],first [temp + 1]);"没有编译器错误。
最终使用strcpy。当我想删除字符串时保持不变,整数取值为0
int main(){
printf("Welcome to address book ! \n ");
printf("--------------------------------------------------------\n");
int a=0;
int temp=0;
char* first[20][30];
char* last[20][30];
int n[20];
int g=0;
while(a<=1000){
int b=0;
printf("What do you want? \n");
printf("1-New ID\n2-Edit ID\n3-Delete ID\n4-List All ID's\n5-Close the Program\n");
printf("--------------------------------------------------------\n");
scanf("%d",&b);
switch(b){
case 1:
printf("Enter Fist Name \n");
scanf("%s",&first[g]);
printf("Enter Last Name\n");
scanf("%s",&last[g]);
printf("Enter Student Number\n");
scanf("%d",&n[g]);
g++;
a++;
continue;
case 2:
printf("Which user you want to change ?\n");
printf("user sequence :");
scanf("%d",&temp);
temp=temp-1;
printf("Listed First Name : %s\n",first[temp]);
printf("New First Name : ");
scanf("%s",&first[temp]);
printf("Listed Last Name : %s\n",last[temp]);
printf("New Last Name : ");
scanf("%s",&last[temp]);
printf("Listed Number : %d\n",n[temp]);
printf("New Listed Number : ");
scanf("%d",&n[temp]);
temp=0;
a++;
continue;
case 3:
printf("which user do you want to delete :");
scanf("%d",&temp);
if(temp+1<=g){
// first[temp]=first[temp+1];
// last[temp]=last[temp+1];
n[temp]=n[temp+1];
}
else
printf("unavailable");
a++;
continue;
case 4:
printf("--------------------------------------------------------\n");
int u;
for(u=0;u<g;u++){
printf(">%d.user. ",u+1);
printf("%d\t",n[u]);
printf("%s\t",first[u]);
printf("%s\n",last[u]);
}
printf("\n--------------------------------------------------------\n");
a++;
continue;
case 5:
printf("\nThank you for the use this program !\n ");
temp= 1000-a;
a= a+temp;
a++;
continue;
}
}
return 0;}