- 论坛徽章:
- 0
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0
typedef struct Info{
char name[20];
char ipaddr[20];
char netmask[20];
char gateway[20];
struct Info *next;
}ipInfo;
int n=0;
ipInfo *create(void){
ipInfo *head,*p1,*p2;
p1=p2=(ipInfo *)malloc(sizeof(struct Info));
scanf("%s%s%s%s",&p1->name,&p1->ipaddr,&p1->netmask,&p1->gateway);
head=NULL;
while(strcmp(p1->name,"exit")!=NULL){
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(ipInfo *)sizeof(struct Info);
scanf("%s%s%s%s",&p1->name,&p1->ipaddr,&p1->netmask,&p1->gateway);
}
p2->next=NULL;
return(head);
}
void output(ipInfo *head){
ipInfo *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do{
printf("%-20s,%-20s,%-20s,%-20s\n",p->name,p->ipaddr,p->netmask,p->gateway);
p=p->next;
}while(p!=NULL);
}
int main()
{
ipInfo *head;
head=create();
output(head);
getche();
}
运行以后,只能输入两次数据,就自动退出了,也不报错~各位帮忙给看看呗,谢谢 |
|