我有一个关于 c 语言函数的问题。我有一个插入数字调用函数的菜单,但问题是我不想使用 for,我想每次按菜单中的选项 a 时一个一个地插入数字。我还想只打印我选择 b 选项时输入的数字。我只是不知道如何解决计数器问题。对不起,如果有语法错误,英语不是我的第一语言。
#include<stdio.h>
//Functions
char menu();
void insert (int[],int);
void print (int[],int);
//******************************
//CUERPO
int main (){
int lenght=5;
int num [lenght];
char option;
while((option=menu())!='x'){
switch (option){
case 'a':
insert(num,largo);
break;
case 'b':
print (num,largo);
break;
}
}
system ("pause");
return 0;
}
/* Codes ************************************************************** */
char menu (){
char option;
printf("\nInsert an option :" );
printf("\nA. insert :" );
printf("\nB. print :" );
scanf("%c", &option);
fflush (stdin);
return option;
}
void insert (int a[], int lenght){ // Here i have the problem
int x=0;
printf("\nInsert your number %d: ", x);
scanf("%d", &a[x]);
x++;
}
void print (int a[], int lenght){
int y;
for(y=0; y<largo; y++){
printf("\nThe numer you have entered are %d: ", a[y]);
}
}