小编ove*_*ood的帖子

位字段给出分段错误

这是C语言.当我运行以下程序时,无论我给出的值有多小,我都会得到运行时分段错误.请帮我找出原因.

#include <stdio.h>
#include <stdlib.h>
struct date
{
unsigned day:
    5;
unsigned month:
    4;
unsigned year:
    12;
};
struct emp
{
    char name[10];
    struct date d;
};
int compare(const void * a, const void * b)
{
    struct emp *orderA = (struct emp *)a;
    struct emp *orderB = (struct emp *)b;
    return (  orderA->d.year - orderB->d.year  );
}
int main ()
{
    int i;
    struct emp e[5];
    for (i = 0;i < 5;i++)
    {
        scanf("%s %d %d %d", e[i].name, e[i].d.day, …
Run Code Online (Sandbox Code Playgroud)

c structure scanf segmentation-fault bit-fields

0
推荐指数
1
解决办法
158
查看次数

标签 统计

bit-fields ×1

c ×1

scanf ×1

segmentation-fault ×1

structure ×1