I need some one to find out the errors please
CODE
#include<stdio.h>
#include<string.h>
#define N 8
struct node {
int data;
struct node* next;
};
struct node* switchpointer;
void wx(int x){ /*Switch List*/
struct node* list[N];
switch(x){
case 1:switchpointer=list[x-1];
break;
case 2:switchpointer=list[x-1];
break;
case 3:switchpointer=list[x-1];
break;
case 4:switchpointer=list[x-1];
break;
case 5:switchpointer=list[x-1];
break;
case 6:switchpointer=list[x-1];
break;
case 7:switchpointer=list[x-1];
break;
case 8:switchpointer=list[x-1];
break;
case 9:switchpointer=list[x-1];
break;
default:printf("Sorry the list is not available\n");
break;
}
}
void p(struct node* switchpointer){ /*Printing the current list using the head switchpointer*/
struct node* current=switchpointer;
while(current!=NULL){
printf("%d\t",current->data);
current=current->next;
}
}
void n(struct node** switchpointer){ /*Delete the current list*/
struct node* current=*switchpointer;
struct node* temp;
while(current!=NULL){
temp=current->next;
deallocate(current);
current=temp;
}
*switchpointer=NULL;
}
struct node* allocate(struct node** newnode) { //Allocate Newnode//
int *AC;
(*AC)++;
*newnode =(struct node*) malloc(sizeof(struct node));
return newnode;
}
void deallocate(struct node* p) { //Deallocate the first node in the current list//
int *DC;
(*DC)++;
free(p);
}
void ax(struct node** newnode,int data){ //Add x to the current list//
allocate(current)=*newnode;
while(current!=NULL){
if(newnode->data!=current->next->data){
current=current->next;
}
else if(newnode->data==current->data){
printf("Number already exist..\n");
break;
}
}
newnode->data=data;
newnode->next=NULL;
}
}
void dy(struct node** head,int data){ //Delete int y from the list//
allocate(current)=*head;
allocate(pre);
pre=current;
while(current!=NULL){
if(current->data==data && current->next==NULL){
deallocate(current);
*head=NULL;
}
else if(current->data!=data){
pre=current;
current=current->next;
}
else if(current->data==data && current->next!=NULL){
pre->next=current->next->next;
deallocate(current);
}
}
if(current==NULL){
printf("List is empty\n");
}
void c(struct node* switchpointer){ //Print the whole current list//
allocate(current);
current=switchpointer;
int i=1;
if(current==NULL)
printf("List is Empty\n");
while(current->next!=NULL){
printf("Node#%d contains:%d\n",i,current->data);
i++;
current=current->next;
}
}
void s(struct node* switchpointer){ //Print the sum of the current list//
int sum=0;
allocate(current);
current=switchpointer;
if(current==NULL){
printf("Empty list Sum=0\n");
}
while(current!=NULL){
sum++;
current=current->next;
}
printf("Sum = %d\n"sum);
}
void gz(struct node** switchpointer,int given){//Overwrite the current nodelist with shwayat fabonnaci//
int i;
n(switchpointer);
for(i=0;i=<given;i++){
ax(switchpointer,fib(i));
}
}
int fib(int num){ //Fabonacci//
if(num==0 || num==1)
return num;
return (fib(num-1)+fib(num-2));
}
}
main(){
struct node* list[N];
switchpointer=list[0]; /*Default switchpointer points to list1*/
int *AC=0; // how many times allocate() was called pointer.//
int *DC=0; //how many times deallocate() was called pointer.//
FILE *hw04;
int numb1;
char str[10];
hw04=fopen("C:/hw04.txt","r");
while(!feof(hw04)){
fscanf(hw04,"%s",str);
if(strcmp(str,"w")==0){
fscanf(hw04,"%d",&numb1);
wx(numb1);
}
else if(strcmp(str,"p")==0){
p(switchpointer);
}
else if(strcmp(str,"n")==0){
n(&switchpointer);
}
else if(strcmp(str,"ax")==0){
fscanf(hw04,"%d",numb1);
ax(&switchpointer,numb1);
}
else if(strcmp(str,"dy")==0){
fscanf(hw04,"%d",numb1);
dy(&switchpointer,numb1);
}
else if(strcmp(str,"c")==0){
c(&switchpointer);
}
else if(strcmp(str,"s")==0){
s(switchpointer);
}
else if(strcmp(str,"g")==0){
fscanf(hw04,"%d",&numb1);
gz(&switchpointer,numb1);
}
else if(strcmp(str,"c")==0){
c(&switchpointer);
}
else if(strcmp(str,"q")==0){
break;
}
printf("#Allocate=%d Deallocate=%d\n",*AC,*DC);
}
fclose(hw04);
}