At 1/24/2007 01:08 PM, you wrote:
>Hey, I have a problem in linked list. I made a little database that
>stores name and secret number. But the problem is that when I want to
>save these data in any file so this data saves but real problem is to
>read data from a file. I had posted earlier this problem on this
>group.Hope I have reached to my answer. Plz solve my problems. Here is
>my code
If you actually wanted to LOAD the old file into memory, you need to
allocate the memory.
Here is a sample in C, not C++
void loadfile(){
FILE *fptr; /*file ponter*/
if( (fptr=fopen(MyFile,"rb")) == NULL) /*if returning NULL*/
printf("Can't open file %s", MyFile);
ptrnew = (struct biodata *) malloc (sizeof(biodata)); /*Gets memory */
ptrprev = ptrfirst = ptrthis = ptrnew; /*save address*/
while(fread(ptrthis, sizeof(biodata), 1, fptr) == 1)
{ /*item return or found*/
ptrnew = (struct biodata *) malloc
(sizeof(biodata)); /*Gets memory */
ptrthis->ptrnext = ptrnew;
printf("\nName: %s", ptrthis->name); /*print contents*/
printf("\nNumber: %04d", ptrthis->num);
printf("\nNext: %p\n", ptrthis->ptrnext);
ptrprev = ptrthis;
ptrthis = ptrnew;
}
fclose(fptr);
ptrprev->ptrnext = 0;
free (ptrnew);
}
Don't forget to define ptrprev.
And, you need to go back to your original program and free all the
memory you allocated before you close.
~Rick
>To unsubscribe, send a blank message to
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>