我在編譯c和.h GCC終端(centos linux)中的ATM代碼項目中的代碼收到以下錯誤。請幫助,因爲我是編程新手。error'expected':',',',';','}'或'__attribute__'before'='token&error:expected')'before'va'
validate_acc.h
#ifndef _VALIDATE_ACC_
#define _VALIDATE_ACC_
struct validate_acc {
int user_acc_try, i = 0;
int user_has_not_entered_right_acc = 1;
int retries = 3;
};
typedef struct validate_acc Validate_acc;
#endif
=========================================== ====
validate_acc.c
#include<stdio.h>
#include "validate_acc.h"
extern int account_number;
void (Validate_acc va)
{
va.user_acc_try, va.i = 0;
va.user_has_not_entered_right_acc = 1;
va.retries = 3;
while(va.retries > 0 && va.user_has_not_entered_right_acc == 1){
printf("\nPlease enter your account number: ");
scanf("%d", &va.user_acc_try);
if(va.user_acc_try != account_number){
printf("You entered the wrong account number\n");
va.retries--;
}
else{
va.user_has_not_entered_right_acc = 0;
}
}
}
====================錯誤
[[email protected] Assignment1]$ gcc -c validate_acc.c
In file included from validate_acc.c:2:0:
validate_acc.h:5:23: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
int user_acc_try, i = 0;
^
validate_acc.c:6:20: error: expected ‘)’ before ‘va’
void (Validate_acc va)
'struct'定義中不允許使用初始值設定項。所以你需要從'struct validate_acc'中刪除所有的'='初始值設定項。 –