我该如何解决我的编译错误以及我应该进行哪些更改以进行改进

时间:2019-01-27 12:22:41

标签: c

源代码在c中的编译错误:

https://i.stack.imgur.com/quF7q.png

请告诉我这个编译错误是什么以及如何解决以及我可以进行哪些更正

2 个答案:

答案 0 :(得分:0)

如果我累积了所有评论以及更多内容:

#include <stdio.h>

int main()
{
  int num;

  printf("enter a number less than 10 : ");
  if (scanf("%d", &num) != 1)
    puts("invalid input");
  else if (num < 10)
    puts("what an obidient savant you are!");
  else
    puts("wrong number");

  return 0; // may be return an other value on error cases ?
}

示例:

pi@raspberrypi:/tmp $ gcc -pedantic -Wall c.c
pi@raspberrypi:/tmp $ ./a.out
enter a number less than 10 : 1
what an obidient savant you are!
pi@raspberrypi:/tmp $ ./a.out
enter a number less than 10 : z
invalid input
pi@raspberrypi:/tmp $ ./a.out
enter a number less than 10 : 20
wrong number

答案 1 :(得分:0)

  • 在C语言中,打印是通过printf()完成的,但是您写了 print()。 (所以您忘记了'f'。)

正确的程序显示为:

int main(int argc, char *argv[]) {
  int num;

  printf("Enter a number less than 10:");
  scanf("%d", &num);

  if (num < 10) {
    printf("What an obedient servant you are!\n");
  }
}

顺便通知\n:它会打印换行符。

相关问题