嘿,我得到了这个错误,我不知道为什么。我对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[]);
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;
}
现在我的另外两个文件
#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;
}
我得到的输出是 错误LNK2019:函数_main
中引用的未解析的外部符号_verifyMIPS我还使用Microsoft Visual Studios开发人员命令提示符来完成所有这些操作。 谢谢你的帮助!
编辑:新问题,当我运行代码时,我输入了32个字符,它将不会运行verifyMIPSInstructions或binToDec。它只会给我一个错误,它显然没有32个字符。有什么建议吗?
答案 0 :(得分:2)
我同意链接器。我没有看到verifyMIPS()
函数ether。也许main()
应该拨打verifyMIPSInstruction()
?