Thanks for the kind words, JC. Interesting working on it. I haven't done much with structs that use pointers to arrays.
37 Replies - 1317 Views - Last Post: 20 November 2012 - 02:05 AM
#32
Re: Saving read file data into structure
Posted 20 November 2012 - 12:30 AM
I added / changed this part of the delete function, to make it more robust - mostly stops counter from becoming less than 0.
j=*counter-1; //new
//Frees up one records allocated memory from the top index
free(friends[j].lname);
free(friends[j].fname);
free(friends[j].home);
free(friends[j].cell);
(*counter)--;
if(*counter<0) //new
*counter=0; //new
printf("\n Name(s) has been deleted\n",j);
return 'a';
}
#33
Re: Saving read file data into structure
Posted 20 November 2012 - 12:34 AM
Adak, on 19 November 2012 - 11:44 PM, said:
Thanks for the kind words, JC. Interesting working on it. I haven't done much with structs that use pointers to arrays.
One last question and I won't bother you again
void print_contact(fr*friends ,int* counter, int i,char buffer[],char user_entry3[50],FILE*read) {
file2(friends ,counter,i,buffer,read,user_entry3);//function call!!
for( i = 0; i < *counter; i++)
if (strlen(friends[i].First_Name) && strlen(friends[i].Last_Name)&& strlen(friends[i].home)&& strlen(friends[i].cell ))
{
getFirst(friends, i);
getLast(friends, i);
getHome(friends, i);
getCell(friends, i);
}
}
when I change the position of the function call to here:
void print_contact(fr*friends ,int* counter, int i,char buffer[],char user_entry3[50],FILE*read) {
for( i = 0; i < *counter; i++)
if (strlen(friends[i].First_Name) && strlen(friends[i].Last_Name)&& strlen(friends[i].home)&& strlen(friends[i].cell ))
{
getFirst(friends, i);
getLast(friends, i);
getHome(friends, i);
getCell(friends, i);
}
file2(friends ,counter,i,buffer,read,user_entry3);//Function calll!!
}
It my contacts list will be blank the first time I check it, but when I check it again the names will be listed from the file. From here I can add a new name, and it appears just once in the contact list before being deleted again. I'm so confused! Oh ya, and this only works when I comment out the fclose statement, otherwise it works once and then is blank again.
This post has been edited by jcmoney1010: 20 November 2012 - 12:38 AM
#34
Re: Saving read file data into structure
Posted 20 November 2012 - 01:08 AM
I can't say too much about it since I haven't seen any of your changes in the code since post #1. Sounds like counter is not being incremented when you add a new record? Or you have 5 records already in the struct array, and that's the size of the records that it was created to hold.
#35
Re: Saving read file data into structure
Posted 20 November 2012 - 01:17 AM
Adak, on 20 November 2012 - 01:08 AM, said:
I can't say too much about it since I haven't seen any of your changes in the code since post #1. Sounds like counter is not being incremented when you add a new record? Or you have 5 records already in the struct array, and that's the size of the records that it was created to hold.
That's what's weird, because outside of what I mentioned in the last post, no changes have been made. the program works once each loop through and then it restarts itself and no changes you made ( deletion or addition) save. Hmm and the plot thickens!
#36
Re: Saving read file data into structure
Posted 20 November 2012 - 01:26 AM
I'd say so! Go get 'em detective!
Worse comes to worse, put the other function back in.
Worse comes to worse, put the other function back in.
#37
Re: Saving read file data into structure
Posted 20 November 2012 - 01:54 AM
Adak, on 20 November 2012 - 01:26 AM, said:
I'd say so! Go get 'em detective!
Worse comes to worse, put the other function back in.
/>
Worse comes to worse, put the other function back in.
I fixed it! the program is fully functional and working, and I couldn't have done it without you. I hope you win the lottery tomorrow, because you deserve it. You really saved me on this one, I will sing your praises throughout the land lol. Have a good one Sir!
#38
Re: Saving read file data into structure
Posted 20 November 2012 - 02:05 AM
You're quite welcome, and I'll give the lottery a go!
/>
Job well done.
Job well done.
This post has been edited by Adak: 20 November 2012 - 02:06 AM
|
|

New Topic/Question
Reply




MultiQuote


|