| ||||||||||
| 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 | |||||||||
高手们帮我看看这程序为什么是access violation#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct node
{
char a[80];
struct node *next;
struct node *pre;
}Node;
Node *head,*p;
/*function poiter int (*p[21])()
visit()
back()
forward() flag
*/
void visit()
{
Node *q;
while(p->next!=NULL)
{
q=p->next;
p->next=q->next;
free(q);
}
q=(Node*)malloc(sizeof(Node));
scanf("%s",q->a);
q->pre=p;q->next=NULL;p->next=q;
p=q;
printf("%s\n",p->a);
}
void forward()
{
if(p->next==NULL)
printf("Ignored\n");
else
{
p=p->next;
printf("%s\n",p->a);
}
}
void back()
{
if(p->pre==NULL)
printf("Ignored\n");
else
{
p=p->pre;
printf("%s\n",p->a);
}
}
void quit()
{
Node *q;
while(p->next!=NULL)
{
q=p->next;
p->next=q->next;
free(q);
}
while(p->pre!=NULL)
{
q=p->pre;
p->pre=q->next;
free(q);
}
free(p);
}
int main()
{
void (*fp[20])();
char word[8];
p=(Node*)malloc(sizeof(Node));
strcpy(p->a,"http://www.acm.org/");
head=p;
p->next=p->pre=NULL;
fp['V'-'B']=visit;
fp['F'-'B']=forward;
fp['B'-'B']=back;
scanf("%s",word);
while(word[0]!='Q')
{
(*fp[word[0]-'B'])();
scanf("%s",word);
}
quit();
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator