Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我运行C程序时什么都没发生?_C_List - Fatal编程技术网

为什么我运行C程序时什么都没发生?

为什么我运行C程序时什么都没发生?,c,list,C,List,我编写了以下代码: #include <stdio.h> #include <stdlib.h> typedef struct { int month; int day; int hour; int minutes; }primaries_date; typedef struct { int all_members; char *country; primaries_date date; }us

我编写了以下代码:

#include <stdio.h>
#include <stdlib.h>


typedef struct 
{
    int month;
    int day;
    int hour;  
    int minutes;
    }primaries_date;

typedef struct 
{
    int all_members;
    char *country;
    primaries_date date;
}usa_primaries;

typedef struct node *ptr;

typedef struct node
{
    usa_primaries up;
    ptr next;
}Node;



void add(ptr *hptr, int members, char *con, int month, int day, int     hour, int minutes)
{
    ptr p = NULL;
    ptr q = NULL;
    ptr t;
    t = malloc(sizeof(Node));
    if(!t)
    {
         printf("Cannot build list");
         exit(0);
    }

    t->up.all_members = members;
    t->up.country = con;
    t->up.date.month = month;
    t->up.date.day = day;
    t->up.date.hour = hour;

   while( (p) )
   {
     if( p->up.date.month >= month || p->up.date.day >= day ||     p->up.date.hour >= hour || p->up.date.minutes >= minutes )
       { 
            q = p;
            p = p->next;
       }
   }

   if(p == *hptr)
   {
        *hptr  = t; /*Resetting head. Assigning to the head t*/
         t->next = p; 
   }
   else
   {
       q->next = t;
       t->next = p;
   }





}

void remove_dates(ptr *hptr, primaries_date date1 , primaries_date date2)
{
    ptr p1 = *hptr;
    ptr p2 = p1;
    while( (p1) && !( (p1->up.date.month == date1.month) &&     (p1->up.date.day == date1.day) && (p1->up.date.hour == date1.hour) && 
           (p1->up.date.minutes==date1.minutes ) ) )
              p1 = p1->next;


          p2 = p1;

    while( (p2) && !( (p2->up.date.month == date2.month) &&    (p2->up.date.day == date2.day) && (p2->up.date.hour == date2.hour) && 
(p2->up.date.minutes==date2.minutes ) ) )
       p1 = p1->next;

    p1->next = p2;

}












void printlist(ptr h)
{
    while(h)
    {
        printf("\n");
   printf("%d %d %d %d %d %s\n", h->up.date.day, h->up.date.month,     h->up.date.hour, h->up.date.minutes, h->up.all_members, h->up.country);
        h = h->next;
    }
}


void freelist(ptr *hptr)
{    
    ptr p;
    while(*hptr)
    {
        p = *hptr;
        *hptr = (*hptr)->next;
        free(p);
   }


}





int main()
{
    ptr h = NULL;
    int month, day, hour, minutes; 
    int all_members; /*Declaration of all_members*/
    char country[256]; 
   char member;

   while( scanf("%d %d %d %d %c  %s",&day,&month,&hour,&minutes,&member,country) == 1)
   {
       if(member == 'Y')
           all_members = 1;
      else
        all_members = 0;
       add(&h,all_members,country,month,day,hour,minutes);
        printlist(h);
   }


freelist(&h);


    return 0;
}
#包括
#包括
类型定义结构
{
整月;
国际日;
整小时;
整数分钟;
}初选日期;
类型定义结构
{
国际大学所有成员;
char*国家;
初选日期;
}美国大学初选;
typedef结构节点*ptr;
类型定义结构节点
{
美国(u)初选上升,;
ptr-next;
}节点;
无效添加(ptr*hptr、整数成员、字符*con、整数月、整数日、整数小时、整数分钟)
{
ptr p=NULL;
ptrq=NULL;
ptr-t;
t=malloc(sizeof(Node));
如果(!t)
{
printf(“无法生成列表”);
出口(0);
}
t->up.all_members=成员;
t->up.country=con;
t->up.date.month=月份;
t->up.date.day=天;
t->up.date.hour=小时;
而((p))
{
如果(p->up.date.month>=month | p->up.date.day>=day | p->up.date.hour>=hour | p->up.date.minutes>=minutes)
{ 
q=p;
p=p->next;
}
}
如果(p==*hptr)
{
*hptr=t;/*重置磁头。分配给磁头t*/
t->next=p;
}
其他的
{
q->next=t;
t->next=p;
}
}
作废删除日期(ptr*hptr,初选日期1,初选日期2)
{
ptr p1=*hptr;
ptrp2=p1;
而((p1)&&!((p1->up.date.month==date1.month)&(p1->up.date.day==date1.day)&&&(p1->up.date.hour==date1.hour)&&
(p1->up.date.minutes==date1.minutes)))
p1=p1->next;
p2=p1;
而((p2)&&!((p2->up.date.month==date2.month)&(p2->up.date.day==date2.day)&&&(p2->up.date.hour==date2.hour)&&
(p2->up.date.minutes==date2.minutes)))
p1=p1->next;
p1->next=p2;
}
无效打印列表(ptr h)
{
while(h)
{
printf(“\n”);
printf(“%d%d%d%d%d%s\n”,h->up.date.day,h->up.date.month,h->up.date.hour,h->up.date.minutes,h->up.all_成员,h->up.country);
h=h->next;
}
}
无效自由列表(ptr*hptr)
{    
ptr-p;
而(*hptr)
{
p=*hptr;
*hptr=(*hptr)->下一步;
自由基(p);
}
}
int main()
{
ptr h=NULL;
int月、日、小时、分钟;
int all_成员;/*所有_成员声明*/
char国家[256];
字符成员;
而(scanf(“%d%d%d%d%c%s”、&day、&month、&hour、&minutes、&member、country)==1)
{
如果(成员='Y')
所有_成员=1;
其他的
所有_成员=0;
添加(&h、所有_成员、国家、月份、日期、小时、分钟);
打印列表(h);
}
自由列表(&h);
返回0;
}
没有编译错误。然而,当我运行程序时,什么都没有发生。 我认为这可能是由于scanf函数造成的,因为scanf在扫描字符时存储“\n”字符(回车键),但我不确定

为什么在我运行程序时什么都没有发生,如何使它正常运行


提前谢谢

scanf
返回它成功解析的转换说明符的数量。因此,假设输入正确,它将返回大于1的值。您应该将它与您实际要求它阅读的项目数进行比较


因此,不用说,如果你使用
scanf
解析输入,不要一次读太多,否则你会在代码中乱扔与神奇数字的比较。

你介意创建一个吗?还有其他(与你当前的问题无关)问题:想一想
usa\u初选
结构中的指针
country
。你指的是什么?你制作的
country
内存是否会指向任何变化?我想我是指向了一个字符串,我不认为我制作的country指向的内存是任何变化的:)@一些程序员,我试图尽可能清楚,因为我不知道问题出在哪里,我发布了完整的代码:)@Sourav ghosh谢谢:)我该如何解决这个问题@StoryTeller@Tree-通过单独调用scanf读取每个变量。那么与1的比较将是正确的,并且您将确切地知道哪个读取失败。谢谢。你是说:@storyteller非常感谢!我仍然不懂一些东西,当(scanf(something)==1)我应该写的时候,我怎么知道这个表单有多少个循环?因为用户只要愿意就可以输入值@StoryTeller@Tree-注意,我写了“已成功解析”。它应该只在输入失败时循环。然后继续下一个字段。