有 3 个文件 - 1. atm.c
(源文件)2. transactions.h
(函数声明)3. transactions.c
(定义函数)当我编译(GCC)时,我得到一个WinMain
错误。
我尝试了所有我知道的方法,我可以编译程序。Ex 1:
gcc -o atm.c transactions.c transactions.h
//atm.c
以这种方式被删除。
例 2:因为我已经在源代码中包含了 file( .h
),所以我没有在编译时给出 .h:
gcc -o atm.c transactions.c
//在这种情况下,文件没有被删除,而是得到了WinMain
错误。
** 输出:**
gcc -o atm.c transactions.c transactions.h
C:/crossdev/src/mingw-w64-v4-git/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
自动取款机:
#include "transactions.h"
int main(void) {
initializeAccount();
getBalance();
//Perform first transaction
askCustomer();
updateAccount(amount);
getBalance();
//Perform second transaction
askCustomer();
updateAccount(amount);
addGift(5.0);
getBalance();
//Perform third transaction
askCustomer();
updateAccount(amount);
addGift(2.0);
getBalance();
thankYou();
return EXIT_SUCCESS;
}
交易.h:
#include <stdio.h>
#include <stdlib.h>
#ifndef TRANSACTIONS_H_
#define TRANSACTIONS_H_
float accountBalance, amount;
void initializeAccount();
void getBalance(void);
void askCustomer(void);
void updateAccount(float value);
void addGift(float giftAmount);
void thankYou(void);
#endif
交易.c:
#include <stdio.h>
#include <stdlib.h>
float accountBalance, amount;
void initializeAccount(void){
accountBalance = 0.0;
}
void addGift(float giftAmount){
accountBalance += giftAmount;
printf("A gift of $%.2f has been added to your \n",giftAmount);
}
void askCustomer(void){
printf("Next transaction please...\n");
printf("Enter amount to credit (positive) or debit (negative):");
scanf("%f",&amount);
}
void getBalance(void){
printf("\ncurrent balance is $%.2f\n", accountBalance);
}
void updateAccount(float amount){
accountBalance += amount;
printf("The account was updated with $%.2f\n",amount);
}
void thankYou(void){
printf("------ Thank you! ------");
}