Lansional 2022-11-27 14:10 采纳率: 91.5%
浏览 1
已结题

输出后的结果格式第一和第二个学生的格式不对称

问题遇到的现象和发生背景

没有报错,只是最后编译后调试框格式不对称

用代码块功能插入代码,请勿粘贴截图
#pragma warning(disable : 4996) 
#include<stdio.h>
#define N 5

struct Student
{
    long num;
    char name[20];
    int score[3];
}st[N];


int main()
{
    struct Student* input(struct Student* p);
    void print(struct Student* pt);
    input(st);
    print(st);
    return 0;
}

struct Student* input(struct Student* p)
{
    int i;
    for (i = 0; i < N; i++, p++)
    {
        printf("enter the data for the %dth student\n", i + 1);
        scanf("%ld %s %d %d %d", &p->num, p->name, &p->score[0], &p->score[1], &p->score[2]);
        printf("\n");
    }
    return p;
}

void print(struct Student* pt)
{
    int i;
    for (i = 0; i < N; i++, pt++)
    {
        printf("num:%ld\tname:%s\tscore:%d\t%d\t%d\n", pt->num, pt->name, pt->score[0], pt->score[1], pt->score[2]);
    }
}

运行结果及报错内容

enter the data for the 1th student
101 Li 90 79 89

enter the data for the 2th student
102 Ma 97 90 68

enter the data for the 3th student
103 Wang 77 70 78

enter the data for the 4th student
104 Fun 67 89 56

enter the data for the 5th student
105 Xue 87 65 69

num:101 name:Li score:90 79 89
num:102 name:Ma score:97 90 68
num:103 name:Wang score:77 70 78
num:104 name:Fun score:67 89 56
num:105 name:Xue score:87 65 69

  • 写回答

2条回答 默认 最新

  • hello_world&& 2022-11-27 14:41
    关注

    可控制一下输出宽度

    printf("num:%5ld\tname:%5s\tscore:%5d\t%5d\t%5d\n",
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月5日
  • 已采纳回答 11月27日
  • 创建了问题 11月27日

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据