C 编程温度转换

标签 c

我是初学者,想知道为什么下面的代码不起作用?我的编译器是Apple Xcode。

问题 1:找不到“conio.h”文件
问题 2:缺少类型说明符,默认为“int”。
问题 3:函数“getch”的隐式声明在 C99 中无效

谁能帮我解释一下上面的意思吗?我一无所知...

<小时/>

下面是我的代码:

#include <stdio.h>
#include <conio.h> //----- ISSUE 1 -----//

main() { //----- ISSUE 2 -----//

  float a, b, centigrade, fahrenheit;
  int x; 

  printf("Press 1:Fahrenheit To Centigrade\nPress 2:Centigrade to  Fahrenheit\n");
  scanf("%d",&x);
  switch(x)
    {
      case 1:
      printf("\nEnter the value of Fahrenheit Temperature:");
      scanf("%f",&a);
      centigrade=5*(a-32)/9;
        printf("Centigrade Temperature:%f\n",centigrade);

          break;

      case 2:
      printf("\nEnter the value of Centigrade Temperature:");
      scanf("%f",&b);
      fahrenheit=((9*b)/5)+32;
        printf("Fahrenheit Temperature:%f\n",fahrenheit);

          break;

      default:
      printf("wrong Input");
      }

getch(); //----- ISSUE 3 -----//

return(0);
}

最佳答案

问题 1: 您的问题是您正在尝试编译最初为 osx 上的 MS-DOS/Windows 终端编写的代码。 conio.h 是一个为 MS-DOS 提供终端用户界面的 header 。

您可以通过将其替换为 curses lib 来解决您的问题

问题 2: main 的签名应为 int main(int argc, char** argv)

问题 3:可能与问题 1 相关,conio.h 不可用,因此其函数的声明(包括 fetch)不可用

关于C 编程温度转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38192560/

相关文章:

c - *p++ 在取消引用后会递增吗?

c - 将排序的多个文件合并为 1 个排序的文件

c - 当我将像素乘以比例因子时图像变黑

c - 指针错误

有人可以帮助我吗,我找不到链表代码中的错误

c - 如何提高 memcpy 的性能

与初始化 char[] 混淆

c - OpenGL 3+ 渲染凹多边形(无 GLU)

无法让我的代码在 c 中工作

c - 向某人解释为什么类型转换不会在编译时自动完成