【问题标题】:program won't compile because of cscanf() and cprintf() [closed]由于 cscanf() 和 cprintf(),程序无法编译 [关闭]
【发布时间】:2020-01-05 14:24:02
【问题描述】:

我正在考虑尝试特殊的控制台函数 cscanf() 和 cprintf() 但以下代码无法编译

#include<stdio.h>
#include<conio.h>
  int main()
{
     int a,b;
     cprintf("Enter two integers\n");
     cscanf("%d%d",&a,&b);
     cprintf("%d+%d=%d",a,b,a+b);
     return 0;
}

这是错误信息:

undefined reference to 'cscanf'
undefined reference to 'cprintf'

【问题讨论】:

  • 请改用printfscanfconio.h 是古老的。
  • does not compile 编译器通常不会给您正确或错误的响应。什么错误?
  • 编译器很可能会告诉您改用_cprintf_cscanf。你至少可以先尝试一下。
  • 为什么人们将其关闭为“与编程无关”?我将其 VTC 为“无 MCVE”。
  • 你从哪里得到这个包含cprintfcscanf的代码?如果它来自与 Turbo C 相关的任何内容,请将其扔掉和/或忘记它。

标签: c gcc codeblocks


【解决方案1】:

gcc 不包含非标准标头 conio.h 或其声明的函数,当使用标准 C 并检查 scanf 是否实际成功时,它看起来像这样:

#include<stdio.h>

int main() {
     int a, b;
     printf("Enter two integers\n");
     if(scanf("%d%d", &a, &b) == 2) {
         printf("%d+%d=%d\n", a, b, a+b);
     } else {
         puts("you failed to input two integers");
     }
     return 0;
}

【讨论】:

  • 我会说"You failed to input two measly integers. Good job."
  • 当我使用 printf() 和 scanf() 时它工作得很好,但是当我使用 cprintf() 和 cscanf() 时程序无法运行。我想知道问题可能是什么。
  • @JL2210 :-) 甚至可以为随机侮辱创建一个生成器。
  • @SportsTV conio.h 及其声明的函数不是标准 C 的一部分。您应该为您所使用的特定环境添加一个标签。
  • @SportsTV 看看这篇维基百科文章:en.wikipedia.org/wiki/Conio.h,如果你使用 gcc 作为编译器,编译器不支持conio.h。实际上,如果我是你,我会忘记 conio.h 曾经存在并坚持标准 C
猜你喜欢
  • 1970-01-01
  • 2022-06-15
  • 2022-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-24
  • 1970-01-01
相关资源
最近更新 更多