Linux中GCC编译报错

来源:百度知道 编辑:UC知道 时间:2024/06/27 10:25:58
void button_clicked(GtkWidget *button,gpointer data){
const char *password = "secret";
const char *password_text=gtk_entry_get_text(GTK_ENTRY((GtkWidget *)data));
count++;
if(count<=3)
disp_count();
if(strcmp(password_text,password)==0)
printf("Access granted!\n");
else
printf("Access denied!\n");
gtk_entry_set_text(GTK_ENTRY(password_entry),"");
else
printf("You try more than three times!\n");
gtk_main_quit();
}

报错:parse error before "else"(指的是倒数第三行的else)

你的条件分支语句多于1,if与else配对出现了冲突,加上花括号就好了
if(count<=3) { // here
disp_count();
if(strcmp(password_text,password)==0)
printf("Access granted!\n");
else
printf("Access denied!\n");
gtk_entry_set_text(GTK_ENTRY(password_entry),""); } // here
else
printf("You try more than three times!\n");
gtk_main_quit();

if(strcmp(password_text,password)==0)
printf("Access granted!\n");
else
printf("Access denied!\n");
gtk_entry_set_text(GTK_ENTRY(password_entry),"");
if和else倒换一下.

strcmp好像只能比较字符串。如果密码含有数字就无法比较了。