Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位大侠帮帮忙啊!为什么总是Presentation Error?#include<stdio.h> #include<string.h> #include<malloc.h> struct url { char site[70]; struct url *next; }; typedef struct url url; url *pipe=NULL;//用以在被调函数和调用函数之间传递数据的全局变量; url *Push(url *unit,url *stack) { if(stack==NULL) { stack=unit; unit->next=NULL; return stack; } else { unit->next=stack; stack=unit; return stack; } } url *Pop(url *stack) { url *unit; if(stack==NULL) return NULL; else { unit=stack; stack=stack->next; pipe=stack; return unit; } } int IsEmpty(url *stack) { if(stack==NULL) return 0; else return 1; } void main() { url *ForwardStack=NULL,*BackStack=NULL,*unit,*unit1; char command[8],website[]={"http://www.acm.org/"}; int i; unit=(url*)malloc(sizeof(url)); for(i=0;i<20;i++) unit->site[i]=website[i]; scanf("%s",command); while(1) { if(strcmp(command,"BACK")==0) { if(IsEmpty(BackStack)==0) printf("Ignored"); else { ForwardStack=Push(unit,ForwardStack); unit=Pop(BackStack); BackStack=pipe; puts(unit->site); } } if(strcmp(command,"FORWARD")==0) { if(IsEmpty(ForwardStack)==0) printf("Ignored"); else { BackStack=Push(unit,BackStack); unit=Pop(ForwardStack); ForwardStack=pipe; puts(unit->site); } } if(strcmp(command,"VISIT")==0) { BackStack=Push(unit,BackStack); unit=(url*)malloc(sizeof(url)); unit->next=NULL; scanf("%s",unit->site); puts(unit->site); while(ForwardStack!=NULL) { unit1=ForwardStack; ForwardStack=ForwardStack->next; free(unit1); } } if(strcmp(command,"QUIT")==0) exit(0); printf("\n"); for(i=0;i<8;i++) command[i]='\0'; scanf("%s",command); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator