fread or fwrite problem....

Discussion in 'C' started by USC_Megoy, Oct 5, 2010.

  1. USC_Megoy

    USC_Megoy New Member

    Joined:
    Oct 5, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi! Im a newbie here....

    I got a problem with my program...My linked list is ok but everytime I export the data to the file, things don't work in a proper way..I will show my code...pls help me...thanks...

    labname[20]="lab445.txt";
    Code:
    /****************FWRITE FUNCTION**********************/
    
    void save_data(information *lab,char labname[])
    {
       FILE *fp;
       int num;
       char temp[15];
    
       strcpy(temp,labname);
       temp[6]='\0';
      /* if(lab==NULL)
    	{ clrscr();
    	  logo();
    	  gotoxy(29,10);printf("%s has an Empty List",temp);
    	  gotoxy(27,14);printf("Press any key to continue..");
    	} */
     
    	 if((fp=fopen(labname,"wt"))==NULL)
    	    { clrscr();
    	      logo();
    	      gotoxy(38,10);printf("Error!");
    	    }
    	  else
    	    { 
    		  if(lab==NULL)
    		     putc('\0',fp);
    		  else
    		   {	num=0;
    			   while(lab!=NULL)
    				   { fwrite(lab,sizeof(information),1,fp);
    					 num++;
    					 lab=lab->next;
    				   }
    				clrscr();
    				printf("There are %d copied from the list.",num);
    				getch();
    				clrscr();
    				logo();
    
    			  for(num=0;numnext;
    
    						temp->next=*lab;
    						*lab=temp;
    
    					x++;
    				   }
    			}
    		  fclose(fp);
    	    clrscr();
    	    printf("There are %d files copied from the file.",x);
    	    getch();
    	  }
    
    
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice