我想在C(VS2010)中實現幾個簡單的函數。應該很容易。但是我收到__cdecl LNK 2019 VS2010 C
錯誤LNK2019:解析外部符號「1> test01.obj:錯誤LNK2019:解析外部符號 「INT __cdecl練習2(INT,INT)」(練習2 @@ YAHHH @ Z?)引用在函數_main 1> test01.obj:錯誤LNK2019:解析外部符號 「空隙__cdecl練習1爲(int *,INT)」(?練習1 @@ @ YAXPAHH Z)在函數引用_main
兩種功能雖然它創建了第一個函數(Ex1)..聲明和原型對我來說很好。 只有一個C函數在其中。 我會很樂意提供任何建議。
#include <stdio.h>
//Function prototypes/////////////////////////////////
void Ex1(int*, int);
int Ex2(int, int);
/////////////////////////////////////////////////////
int main()
{
int select = 0, i, all_Ex_in_loop = 0, arrsize = 0;
int a = -3, b = 13; // EX 2 variables
int* arrPtr; //EX1 definitions
int arr[] =
{ 7, 5, -8, 3, 4, 21, -10, -3, 2, 4 };
arrsize = sizeof(arr)/sizeof(int);
arrPtr = arr;
printf(
"Run menu once or cyclically?\n(Once - enter 0, cyclically - enter other number) ");
if (scanf_s("%d", &all_Ex_in_loop) == 1)
do
{
for (i = 1; i <= 5; i++)
printf("Ex%d--->%d\n", i, i);
printf("EXIT-->0\n");
do
{
select = 0;
printf("please select 0-5 : ");
scanf_s("%d", &select);
} while ((select < 0) || (select > 5));
switch (select)
{
case 1:
Ex1(arrPtr, arrsize);
break;
case 2:
Ex2(a, b);
break;
//case 3: Ex3(); break;
//case 4: Ex4(); break;
//case 5: Ex5(); break;
}
} while (all_Ex_in_loop && select);
return 0;
}
// ---------------------------------------------- EX1 -------------------------------------------------------------
void Ex1(int* ptr, int size)
{
int i;
printf("Original array: ");
for (i = 0; i < size; i++)
{
printf("%d, ", ptr[i]);
}
for (i = 1; i < size; i++)
{
ptr[i] += ptr[i - 1];
}
printf("\n Updated array: ");
for (i = 0; i < size; i++)
{
printf("%d, ", ptr[i]);
}
printf("\n");
}
//---------------------------------------------------------------- EX2 ------------------------------------------------------------
int Ex2(int a, int b)
{
int firstVal = 0, secVal = 0, num = 0;
printf("Please enter numbers. -1 to finish: ");
while (num != -1)
{
scanf_s("%d", &num);
if (num > (a + b)/2 && num < b)
{
firstVal += num;
}
if (num > a && num < (a + b)/2)
{
secVal += num;
}
}
printf("\n The value is: %d", firstVal + secVal);
return firstVal + secVal;
}
無法重現。 – Stargateur