#include <stdio.h>
main() {
    int data1, data2;
    char op;
    printf("Please enter the expression data1+data2:\n");
    scanf_s("%d%c%d", &data1, &op,&data2);
    printf("%d%c%d = %d\n", data1, op, data2, data1 + data2);
}

报错:

函数scanf_s的字符输入

原因:用scanf_s()输入字符或字符串,需要遵循下面格式:

scanf_s("%s",a,20);        /*a,20中的 ,20 是用来指定缓冲区大小的参数,表示最多读取n-1个字符,不加的话,编译器会出错,无法进行正常的字符串输入*/

 

 

 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-22
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2022-01-13
相关资源
相似解决方案