[問題]請問如何在c語言正確輸入字元???
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Symptom
{
int id; //唯一的症狀編號;如同身分證號,與學號,用來表示該項症狀
char name[100]; //症狀名稱
};
int strstrcmp(char string[],struct Symptom a[],int count)
{
for(int i=0;i<count;i++)
{
if(strcmp(string,a[i].name)==0)
{
return -1;
}
}
return 0;
}
void output1(struct Symptom a[],int count)
{
for(int i=0;i<count;i++)
{
a[i].id=i+1;
printf("%s %d\t",a[i].name,a[i].id);
}
}
int main(void)
{
struct Symptom a[100];
struct Symptom temp;
int input,count=0;
char aa=' ',bb=' ';
do{
printf("1)編輯症狀 6)結束:");
scanf("%d",&input);
if(input==1)
{
do{
printf("功能選單:A)輸入 B)印出全部 C)回上層:");
scanf("%c", &aa);
if(aa=='A')
{
printf("症狀名稱:");
scanf("%s",temp.name);
if(count!=0)
{
if(strstrcmp(temp.name,a,count)==-1)
{
printf("症狀名稱名稱重複!\n");
continue;
}
}
a[count]=temp;
count++;
}
if(aa=='B')
{
output1(a,count);
}
}while(aa!='C');
continue;
}
}while(input!=6);
return 0;
}
為什麼"功能選單:A)輸入 B)印出全部 C)回上層:" 會連續出現2次
aa有初始值 卻總是還沒輸入就有奇怪的值在裡面
其他功能都還ok
就是這邊出問題
可以幫個忙嗎????
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.72.84.170
→
03/16 10:50, , 1F
03/16 10:50, 1F
※ 編輯: heyra 來自: 203.72.84.170 (03/16 11:01)
→
03/16 11:06, , 2F
03/16 11:06, 2F
推
03/16 11:06, , 3F
03/16 11:06, 3F
→
03/16 11:07, , 4F
03/16 11:07, 4F
→
03/16 11:07, , 5F
03/16 11:07, 5F
→
03/16 11:07, , 6F
03/16 11:07, 6F
→
03/16 11:19, , 7F
03/16 11:19, 7F
推
03/16 11:20, , 8F
03/16 11:20, 8F
→
03/16 11:23, , 9F
03/16 11:23, 9F
→
03/16 11:24, , 10F
03/16 11:24, 10F
→
03/16 11:24, , 11F
03/16 11:24, 11F
→
03/16 11:24, , 12F
03/16 11:24, 12F
→
03/16 11:28, , 13F
03/16 11:28, 13F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章