void readStateTransitions(state *s){
char kok[20];
char y;
int j=0;
do{
char alpha=' ';
printf("Enter the alphabet\t ");
scanf("%c", &alpha );
//s->TrasitionsArray[j]->label=alpha;
s->TrasitionsArray[j] = (struct trans*)malloc(sizeof(struct trans));
s->TrasitionsArray[j]->from = (struct state *)malloc(sizeof(struct state));
s->TrasitionsArray[j]->to = (struct state *)malloc(sizeof(struct state));
printf("For %s",s->label);
//printf("Enter the next state for %s under %c",StatesArray[i].label,alphabet[j]);
printf("Enter the next state under %c",alpha);
scanf("%s",kok);
for(int k=0;k<StatesNumber;k++){
if(strcmp(StatesArray[k].label,kok)==0){
s->TrasitionsArray[j]->to=&StatesArray[k];
}
}
s->TrasitionsArray[j]->from=s;
s->TrasitionsArray[j]->label=alpha;
j++;
printf("\n\n more transitions..??(y/n)");
}while(getch()=='y');
}
我有这段代码,这里要求用户输入两个变量,一个用于 alpha(char),第二个用于 kok(string),但问题是程序忽略了变量 alpha 并直接移动到变量 kok
图片链接http://imageshack.us/photo/my-images/194/capturejey.jpg/