file problem

Reply

Join Date: Jun 2009
Posts: 14
Reputation: sam511 is an unknown quantity at this point 
Solved Threads: 0
sam511 sam511 is offline Offline
Newbie Poster

file problem

 
0
  #1
Jun 27th, 2009
hi , I'm trying to store linked list in a file . I opened a file with extension txt but when I opened it to read it . It was encrypted
does anyone know why??
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 72
Reputation: kolosick.m188 is an unknown quantity at this point 
Solved Threads: 15
kolosick.m188's Avatar
kolosick.m188 kolosick.m188 is offline Offline
Junior Poster in Training

Re: file problem

 
0
  #2
Jun 27th, 2009
How did you open it. Can you post the code
There are 10 types of people in the world, those who get this, those who don't, and those who thought this was binary.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: sam511 is an unknown quantity at this point 
Solved Threads: 0
sam511 sam511 is offline Offline
Newbie Poster

Re: file problem

 
0
  #3
Jun 27th, 2009
Thanks It opened when I put run again I have another problem I'm using two linked lists and I opened two files for each one but when I write list to file It writes both lists in the two files .

here is the code
void save (school *c,school *m)
{




fpta=fopen("school.txt", "w");

fptb=fopen("school1.txt", "w");

c=head;
m=head;

while(c!=NULL)
{
fprintf(fpta,"\n%d\n%s\n%s\n%d\n%s\n%d\n%f",c->id,c->name,c->address,
c->phone,c->sex,c->level,c->average);
c=c->next;
}

fclose(fpta);

printf("\nFile one has been saved");


while (m!=NULL)

{
fprintf(fptb,"\n%d\n%s\n%s\n%d\n%s\n%d\n%f",m->id,m->name,m->address,
m->phone,m->sex,m->level,m->average);

m=m->next;

}

fclose(fptb);

printf("\nFile two has been saved");


getch();

}
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 481
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 80
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

Re: file problem

 
0
  #4
Jun 27th, 2009
>I have another problem I'm using two linked lists and I opened two files for each one but when I write list to file It writes both lists in the two files .

You are using c and m as two pointers to mark the two lists right? Thats the reason you are passing them.But why this?
  1. c=head;
  2. m=head;
by this you are making both c and m point to head so whats the use of passing them to the function ???

Well you have opened your files fpta and fptb in mode "w" write mode and so it would delete all the contents of it next time you open it and write fresh so have a look at it.
Last edited by csurfer; Jun 27th, 2009 at 10:59 pm.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: sam511 is an unknown quantity at this point 
Solved Threads: 0
sam511 sam511 is offline Offline
Newbie Poster

Re: file problem

 
0
  #5
Jun 27th, 2009
I used a condition according to level number and it worked .but I think the problem is with add function .I'll post the structure and add function .If anyone could correct it.
here is the code
typedef struct school {
int id;
char name[80];
char address[80];
int phone;
char sex[10];
int level;
float average;
struct school *next;


}school;

struct school*last=NULL,*head=NULL;
struct school *student1;//pointer to list one
struct school *student2;//pointer to list two

void add(struct school *one)
{
/*struct*/
one = (school *) malloc (sizeof(school));
printf("\n\t\t Add The Information To system " );
printf("\n\t\t\tID : ");
scanf(" %d", &one->id);


printf("\t\t\tNAME : ");
scanf("%s" , one->name);


printf("\t\t\tAddress : ");
scanf(" %s",one->address);


printf("\t\t\tphone : ");
scanf("%d" , &one->phone);


printf("\t\t\tsex : ");
scanf("%s" , one->sex);


printf("\t\t\tlevel : ");
scanf("%d" , &one->level);


printf("\t\t\taverage : ");
scanf("%f" , &one->average);


one->next = NULL;


if (head == NULL)
{
last = one;
head = one;
}
else
{
last->next = one;
last = one;
}



printf("\n\n******************************");

return;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2,226
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 273
BestJewSinceJC BestJewSinceJC is offline Offline
Nearly a Posting Maven

Re: file problem

 
0
  #6
Jun 27th, 2009
I'd say your first problem is your inability to use code tags, leading to nobody caring enough to waste their time to read your code.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: sam511 is an unknown quantity at this point 
Solved Threads: 0
sam511 sam511 is offline Offline
Newbie Poster

Re: file problem

 
0
  #7
Jun 27th, 2009
I'm sorry .I was in such a hurry and I forgot .sorry
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: sam511 is an unknown quantity at this point 
Solved Threads: 0
sam511 sam511 is offline Offline
Newbie Poster

Re: file problem

 
0
  #8
Jun 27th, 2009
could anyone define the problem in my code .please!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3,911
Reputation: adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future 
Solved Threads: 704
Moderator
adatapost adatapost is offline Offline
Senior Poster

Re: file problem

 
1
  #9
Jun 28th, 2009
sam511,

I think you tried to open a data file with an editor. There are two types of data file - Text and Binary.
Show us your complete code. Don't forget; wrap up source code with BB code tags.

Another post ?

http://www.daniweb.com/forums/thread200229.html
Last edited by adatapost; Jun 28th, 2009 at 3:11 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 375 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC