我正在学习C语言,我尝试了一个使用scanf()的简单程序,这个程序一直给我一个错误。代码如下:

#include<stdio.h>
int area;//global variable
int main ()
{
int a, b;//local variables

/*actual initialization*/
printf("enter the value of side a:");
scanf("%d", &a);

printf("enter the value of side b:");
scan("%d", &b);
printf("\n");
printf("\t you have entered %d for side a
and %d for side b\n",a,b);

area=a*b;
printf("\t the area of your rectangle is
:%d \n",area);

return 0;
}

这是我得到的输出的一部分:
LIBS     = -L"C:/Program Files (x86)/Dev-
Cpp/MinGW64/lib" -L"C:/Program Files
(x86)/Dev-Cpp/MinGW64/x86_64-w64-
mingw32/lib" -static-libgcc
INCS     = -I"C:/Program Files (x86)/Dev-
Cpp/MinGW64/include" -I"C:/Program Files
(x86)/Dev-Cpp/MinGW64/x86_64-w64-
mingw32/include" -I"C:/Program Files
(x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-
mingw32/4.8.1/include"
CXXINCS  = -I"C:/Program Files (x86)/Dev-
Cpp/MinGW64/include" -I"C:/Program Files
(x86)/Dev-Cpp/MinGW64/x86_64-w64-
mingw32/include" -I"C:/Program Files
(x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-
mingw32/4.8.1/include" -I"C:/Program Files
(x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-
mingw32/4.8.1/include/c++"
BIN      = "c+ flo project.exe"
CXXFLAGS = $(CXXINCS)
CFLAGS   = $(INCS)
RM       = rm -f

.PHONY: all all-before all-after clean
clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)

Untitled6.o: Untitled6.c
$(CC) -c Untitled6.c -o Untitled6.o
$(CFLAGS)

从我周围的阅读中,我了解到它是一个链接器错误,但我不知道如何修复它。我使用DEV C++。请帮忙

最佳答案

$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)

这不是错误信息。是命令链接你的程序。或者更确切地说,大多数变量将被扩展到正确的链接器命令。例如,$(CC)将变成编译器的名称(它也在进行链接),$(LINKOBJ)将是编译Untitled6.c产生的目标文件,它可能是保存程序代码的文件。
您没有发布错误消息,但是当我尝试运行您的程序时,我在此处收到一个错误:
scan("%d", &b);

这可能是一个输入错误,您的意思是scanf而不是scan。还有,那些指纹
printf("\t you have entered %d for side a
and %d for side b\n",a,b);

不工作,因为换行符正在断开字符串文本。它应该都在一行上(或者可以在一行的末尾加一个\,让编译器“忽略”换行符,但我现在不建议这样做)。但我认为这只是粘贴代码的结果,而且在程序中是正确的。
由于您没有找到错误消息(但还有许多其他有趣的输出),请尝试在DEV C++中找到实际的错误消息,这样您就知道下一次出现错误时该在哪里查找。对我来说,错误信息是identifier "scan" is undefined,对你来说可能是类似的。

关于c - 如何解决$(CC)$(LINKOBJ)-o $(BIN)$(LIBS),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53610481/

10-10 16:26