【发布时间】:2016-01-14 16:16:36
【问题描述】:
我正在尝试编写一个可以创建结构数组的代码。我仍处于尝试将结构传递给函数的早期阶段,虽然我认为必须使用指针,但我只是不知道如何正确地做到这一点。下面是我的代码。
#include <stdio.h>
struct age{
int num;
};
struct name{
char fname [15];
char lname[15];
struct age nameAge;
};
void input(struct name *info[]);
int main (void){
char choice;
char ans;
int i;
struct name record[10];
do{
printf("M E N U");
printf("\n\n[I]nput\n[D]isplay\n[S]earch\n[Q]uit");
printf("\n\nEnter choice: ");
choice=tolower(getche());
system("cls");
switch (choice){
case 'i': input(&record[]);
i++;
break;
case 'd': //function here
break;
case 's': //fucntion here
break;
case 'q': printf("The program will now close.");
break;
default: printf("Invalid character. Try again");
break;
}
getch();
system("cls");
}while (choice!='q');
return 0;
}
void input(struct name *info[]){
//codes here
}
【问题讨论】:
-
为什么
input(&record[]);?? -
旁白:你需要
#include更多的库头文件——至少ctype.h、conio.h和stdlib.h。您应该收到编译器警告。而char choice;应该是int choice;与getche和tolower的返回类型相同。 -
注意:你还没有初始化
i。
标签: c arrays function structure