vc6.00能运行的C语言程序在VS2017中得不到结果

KEYBOSS_ 2017-09-20 11:50:57
#define N 1
#include<stdio.h>
struct student
{
char num[6];
char name[8];
int score[4];
}stu[N];
void inputstu(struct student stu[])
{
int i, j;
for (i = 0; i<N; i++)
{
printf("\n please input %d of %d\n", i + 1, N);
printf("num:");
scanf("%s", stu[i].num);
printf("name:");
scanf("%s", stu[i].name);
for (j = 0; j<3; j++)
{
printf("score %d", j + 1);
scanf("%d", &stu[i].score[j]);
}
printf("\n");
}
}


void printstu(struct student stu[])
{
int i, j;
printf("\nNo.Name Sco1 Sco2 Sco3\n");
for (i = 0; i<N; i++)
{
printf("%6s%10s", stu[i].num, stu[i].name);
for (j = 0; j<3; j++)
printf("%-8d", stu[i].score[j]);
printf("\n");

}
}

void main()
{
inputstu(stu);
printstu(stu);
}
在VC6.00能打印出结果;
但是在VS2017中只能输入数据不能打印;
...全文
402 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2017-09-21
  • 打赏
  • 举报
回复
程序没问题,应该是编译器输出时需要处理一下。在Linux下不做修改也可以输出数据。
棉猴 2017-09-21
  • 打赏
  • 举报
回复
或者像1楼说的那样,在main()函数的最后田间
system("pause");
并且在源文件的起始位置处添加
#include <stdlib.h>
棉猴 2017-09-21
  • 打赏
  • 举报
回复
没有VS2017,在VS2015上调试的。主要把scanf改为scanf_s,把printf()中表示宽度的数字进行了修改
void inputstu(struct student stu[])
{
int i, j;
for (i = 0; i<N; i++)
{
printf("\n please input %d of %d\n", i + 1, N);
printf("num:");
scanf_s("%s", stu[i].num, 6);
printf("name:");
scanf_s("%s", stu[i].name, 8);
for (j = 0; j<3; j++)
{
printf("score %d", j + 1);
scanf_s("%d", &stu[i].score[j]);
}
printf("\n");
}
}


void printstu(struct student stu[])
{
int i, j;
printf("\nNo.Name Sco1 Sco2 Sco3\n");
for (i = 0; i<N; i++)
{
printf("%3s%5s", stu[i].num, stu[i].name);
for (j = 0; j<3; j++)
printf("%-4d", stu[i].score[j]);
printf("\n");

}
}


OldHello 2017-09-21
  • 打赏
  • 举报
回复
在最末尾加一个system("pause"); 可能要加头文件#include <process.h>

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧