Trying to do something fairly basic but am getting caught up on it. I am trying to extract text from a .txt file into an array line by line and then dissect that line into various parts, each part separated by a comma and placed into a different variable.
ie.
0001,dog,3,five,123
0002,cat,7,four,985
0003,pig,2,six_,435
0005,cow,4,nine,999
so when i dissect it, it comes out as:
four_num = 0001
animal = dog
one_num = 3
wordnum = five
three_num = 123
I have done this the long way, character by character in the array pulling it out and placing it in another variable. But this is long and clunky and requires it to be spot on with no flexibility.
What I hope to achieve is to be able to search until next comma and place all data before that into the variable (ie. four_num)
I have tried doing this a few ways, various looping methods, setting counters to count the number of commas that have been detected in the line buffer - to no avail.
I am trying to avoid as many prebuilt functions as I can as this is for an embedded project that it sort of memory sparse.
Expand|Select|Wrap|Line Numbers
- if(b<21) // 21 good length for config.txt format, no cutting - reads in full.
- { // inc line termination chars.
- tempstring[b]=c;
- b++;
- }
- if(b==21) // has read off 1st 10 chars and now can under go various condition tests
- { // buffer full string length ten
- for(b=0;b<21;b++)
- ushell_putchar(tempstring[b]);
- b=0;
- for(b=0;b<21;b++)
- {
- if(tempstring[b]==',')
- {
- com_cnt++;
- }
- if(tempstring[b]!=',' )
- {
- str_comm[b]=tempstring[b];
- ushell_putchar(str_comm[b]); // parsed to commerless string --> what to do with?
- }
- }
- b=0;
- com_cnt=0;
if(com_cnt==1)
four_num[b]=tempstring[b];
I have got it in the bottom section of code there to pull all the commas out and then print the new comma-less string out however.
I am using WINGCC with avr studio 4.13 - no real platform issues that will come up though, its a matter of the correct algorithm
Any help will be much appreciated! thank you all in advance!
I know tis going to be so easy and brain dead when I see it, but till then...