C 错误LNK2019:未解析的外部符号
嘿,我得到了这个错误,我不知道为什么。我是C语言的新手,希望不会太复杂 这是我的主要工作C 错误LNK2019:未解析的外部符号,c,compiler-errors,mips,C,Compiler Errors,Mips,嘿,我得到了这个错误,我不知道为什么。我是C语言的新手,希望不会太复杂 这是我的主要工作 #include <stdio.h> #include <stdlib.h> #include <string.h> #include "binToDec.c" #include "verifyMIPS.c" int binToDec(char string[], int begin, int end); int verifyMIPS (char string[]);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "binToDec.c"
#include "verifyMIPS.c"
int binToDec(char string[], int begin, int end);
int verifyMIPS (char string[]);
int main(int argc, char *argv[])
{
char buffer[BUFSIZ];
FILE* fptr; /* file pointer */
int lineNum = 0;
int i;
char *count;
/* Was a file passed in a parameter (e.g., on the command line)? */
if ( argc == 2 )
{
/* Open the file for reading */
if ((fptr = fopen (argv[1], "r")) == NULL)
{
fprintf (stderr, "Error: Cannot open file %s.\n", argv[1]);
return 1;
}
}
else /* No file passed in; use standard input. */
fptr = stdin;
/* Continuously read next line of input until EOF is encountered.
* Each line should contain only 32 characters and newline.
*/
while (fgets (buffer, BUFSIZ, fptr)) /* fgets returns NULL if EOF */
{
lineNum++;
if (strlen (buffer) == 33 && buffer[32] == '\n')
buffer[32] = '\0'; /* convert newline to null byte */
else
{
(void) fprintf (stderr,
"Error: line %d does not have 32 chars.\n", lineNum);
continue; /* error: get next line */
}
/* Verify that the string is 32 0's and 1's. If it is, do
* various tests to ensure that binToDec works correctly.
* If the string contains invalid characters, print an error
* message.
*/
/* CODE MISSING !!! */
int i;
for(i=0; i<33; i++)
{
if(verifyMIPS(buffer[i])==1)
{
binToDec(buffer[i],0,32);
}
else
{
(void) fprintf (stderr,
"Error: line %d does not have 32 chars.\n", lineNum);
continue; /* error: get next line */
}
}
}
/* End-of-file encountered; close the file. */
fclose (fptr);
return 0;
}
我得到的结果是
错误LNK2019:未解析的外部符号_verifyMIPS在函数_main中引用
我还使用MicrosoftVisualStudioDeveloper命令提示符来实现所有这些。
谢谢你的帮助
编辑:新问题,当我运行代码并输入32个字符时,它将不会运行verifyMIPSInstructions或binToDec。它只会给我一个错误,它没有32个字符时,它显然有。有什么建议吗?我同意链接者的意见。我没有看到
verifyMIPS()
函数。也许main()
应该调用verifyMIPSInstruction()
?大多数人大多数时候都不#包含C源文件。您通常包括头,而不是源代码。一种可能是您有CRLF行结尾,并且文件正在以二进制模式处理,因此行似乎较长,因为'\r'
在'\n'
之前。我认为这不应该是问题所在;您没有在fopen()
中指定“rb”
,但它可能会影响stdin
。但是,如果您没有获得正确的长度,您生成的诊断应该(a)报告您获得的长度,并且(b)打印输入的每个字符,可能是十六进制(%3x”
)而不是使用%c
,这样您就可以看到计算机认为它得到了什么,并将其与您认为得到的进行比较。啊,我需要一些睡眠。谢谢现在我有一个新问题,我将编辑我的问题。
#include <string.h>
int verifyMIPSInstruction (char * instr)
/* returns 1 if instr contains 32 characters representing binary
* digits ('0' and '1'); 0 otherwise
*/
{
int i;
for(i = 0; i<32; i++)
{
if(instr[i] == '1' || instr[i] == '0')
{
return 1;
}
}
if(instr[32] != '\0')
{
(void) printf("is not an instruction");
}
return 0;
}
int binToDec(char string[], int begin, int end)
{
int i, remainder;
int j = 1;
int decimal = 0;
i = atoi(string);
while(i !=0)
{
remainder = i%10;
decimal = decimal+remainder*j;
j=j*2;
i = i/10;
}
printf("equivalent decimal value: %i", decimal);
return decimal;
}