即使我确信我的代码没有问题,它仍然告诉我存在构建错误:
#include <stdio.h>
#include <string.h>
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_DEPRECATE
typedef struct
{
char name[50];
char ID[10];
int age;
int grades[5];
}Student;
int main()
{
Student student1;
strcpy(student1.name, "Abood");
strcpy(student1.ID, "1034913");
student1.age = 15;
student1.grades[0] = 2;
student1.grades[1] = 32;
student1.grades[2] = 424;
student1.grades[3] = 43;
student1.grades[4] = 5;
for (int i = 0; i < 5; i++) printf("grade[%d] = %d", i, student1.grades[i]);
return 0;
}
我基本上尝试了一切。如果我不使用 scanf,我也会面临同样的问题 #define _CRT_SECURE_NO_WARNINGS 尽管我之前没有遇到过这个问题,而且我不需要包含该预处理器指令。
您已被警告构建错误,因为您试图在错误的位置抑制警告。它们应该放在 #include
指令之前
。
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
请注意,许多警告本质上都是微软浪漫的。 C 标准尚未弃用 scanf()
(尽管您在这里不使用它)。微软希望将您与它自己的据称更安全的功能版本联系起来。