我在嘗試編譯時遇到這些錯誤,唯一加下劃線的是 strcpy_s(name, strlen(input) 1, input); 這是警告。這是作業的一部分,部分說明是制作 Topic.c(下面的代碼)和 Topic.h,但沒有說明在 .h 檔案中放入什么內容。我以前從未見過這些錯誤并對其進行了研究,但我找不到與此問題相關的參考資料。這不是一個修復代碼分配,它應該可以運行我只應該理解這些概念。不知道要問什么問題。我已經檢查了幾次以確保代碼輸入正確。
函式“int __cdecl invoke_main(void)”(?invoke_main@@YAHXZ) 中參考了 LNK2019 未決議的外部符號主
和
LNK1120 1 未解決的外部因素
和 1 個警告
C6387 'name' 可能是 '0':這不符合函式 'strcpy_s' 的規范。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Swap 1 method with scalars: why does this not work?
*/
void swap1(int x, int y)
{
int temp = x;
x = y;
y = temp;
}
/*
* swap 2 method with pointers: why does this work?
*/
void swap2(int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}
/*
* Play Pointer method: Don't forget to clean up your malloc!
*/
char* playPointer(char* input)
{
// Allocate memory to hold a copy of the input array, copy input to it, and
return a pointer to a new array
// What is the advantage of assigning address of a variable to a pointer
variable?
// Why does swap1() not work, and why does swap2() work?
// How does strpy_s() make code more secure?
// How does strpy_s() demonstrate defensive coding?
// Look up strncpy() and compare it to strpy_s() How are they similar?
char* name = malloc(strlen(input) 1);
strcpy_s(name, strlen(input) 1, input);
return name;
}
uj5u.com熱心網友回復:
您的代碼中沒有main函式。
語言中的main函式C是程式入口點,它必須存在才能運行已編譯的程式。
在您的情況下,聯結器找不到它并報告錯誤。
uj5u.com熱心網友回復:
如果這應該是一個獨立的程式,而不是鏈接到其他程式的東西,它需要一個main()函式。
要禁止有關 的警告name,請將呼叫的代碼包裝在檢查成功strcpy_s()的if陳述句中malloc()。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Swap 1 method with scalars: why does this not work?
*/
void swap1(int x, int y)
{
int temp = x;
x = y;
y = temp;
}
/*
* swap 2 method with pointers: why does this work?
*/
void swap2(int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}
/*
* Play Pointer method: Don't forget to clean up your malloc!
*/
char* playPointer(char* input)
{
// Allocate memory to hold a copy of the input array, copy input to it, and return a pointer to a new array
// What is the advantage of assigning address of a variable to a pointer variable?
// Why does swap1() not work, and why does swap2() work?
// How does strpy_s() make code more secure?
// How does strpy_s() demonstrate defensive coding?
// Look up strncpy() and compare it to strpy_s() How are they similar?
char* name = malloc(strlen(input) 1);
if (name != NULL) {
strcpy_s(name, strlen(input) 1, input);
}
return name;
}
int main(void) {
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/418545.html
標籤:
