我想在C中創建我自己的函數,然後將#include
與頭文件一起使用。我知道如何製作頭文件,並且我寫了.c函數。但是,當我嘗試編譯.c時,出現'[Linker error]未定義的'WinMain @ 16'引用錯誤,並且無法編譯。 然後,如果我嘗試在程序中使用它,它會顯示'[Warning]文件末尾沒有換行',然後'[Linker error]未定義的引用validf(int,int,int)'。 任何人都可以幫忙嗎?如何正確地創建一個C函數(包括頭文件)
功能代碼:
int validf(int current,int max, int zero)
{
if(zero==1)
{
if(current>max || current<0)
{
printf("Invalid Input");
return 0;
}
else
{
return 1;
}
}
else if(zero==0)
{
if(current>max || current<=0)
{
printf("Invalid Input");
return 0;
}
else
{
return 1;
}
}
else
{
printf("Invalid parameters");
return -1;
}
}
主要代碼:
#include<stdio.h>
#include<stdlib.h>
#include "validf.h"
int main()
{
int valid=0;
valid=validf(4,5,0);
printf("%d",valid);
system("\npause");
return 0;
}
頁眉代碼:
#ifndef VALIDF_H_
#define VALIDF_H_
int validf(int current,int max,int zero);
#endif
你寫了'main'函數嗎? – Transcendental
你在用什麼IDE?如果你使用Eclipse,你可能必須首先保存文件並編譯。 –
代碼是標題應該添加的函數,而不是使用函數的代碼。我使用Dev C++(我不是我的錯,我們別無選擇)。 – MrGalax1