Иметь 3 файла - 1. atm.c
(Исходный файл) 2. transactions.h
(объявления функций) 3. transactions.c
(определение функций), когда я компилирую (GCC) это я получаю WinMain
Ошибка,
И я попробовал все способы, которые я знаю, что я могу скомпилировать программу.Пример 1: gcc -o atm.c transactions.c transactions.h
// atm.c
удаляется таким образом.
Пример 2: поскольку я уже включил файл (.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
атм.c:
#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;
}
Transactions.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
Transactions.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! ------");
}