![]() |
Cannot load text files to structure properly.
Dear ALL,
I am trying to load a few lines ( many strings seperated by a space) from a text file and break them into string tokens and store it as structure fields. This functions should be performed by the load_items(item); function. However there is an anomaly. When i print the structure fields to check if they have been loaded properly, it turns out they are not!. when i print structure fields outside the load_items(item); function the fields genre, borrower, availability, due_date do not seem to be stored properly in the array. The following code is the main function and the load_items function. Code:
#include <stdio.h>Below is the contents of the items2.txt file. Code:
eng_math cn_4 croft book learning xxxx 1 00/00/00 |
Re: Cannot load text files to structure properly.
Remember the terminating NULL!
Code:
char availability[1]; |
Re: Cannot load text files to structure properly.
Dear Mr xpiotos,
Like you had told me, I changed availability[1] to 2. so now the outcome is better but it the genre from the string token does not seem to get into the stucture field genre. You can notice the missing word "learning" in the print out . why is that? I am not sure, Please lend a hand. THANKS. Code:
char availability[2]; |
Re: Cannot load text files to structure properly.
Remember what I said before about terminating NULLs? You still have such a problem - now it's up to you to find it.
|
Re: Cannot load text files to structure properly.
Thanks Mr xpiotos, You were absolutely right. That was the problem. for example due date (00/00/00)was only give 8 spaces but in fact it needed 9. After fixing this it worked. great work. Thanks Again. SILLY ME!
|
| All times are GMT +5.5. The time now is 01:13. |