converting string[][] to float[]

Reply

Join Date: Oct 2007
Posts: 41
Reputation: mank is an unknown quantity at this point 
Solved Threads: 0
mank mank is offline Offline
Light Poster

converting string[][] to float[]

 
0
  #1
Oct 24th, 2007
I am trying to convert some data that I read in file as string data to a float array

The data that is read are in two dimensional string array like
  1. char tmatrix[10][100];
  2. for(j=0;j<k3;j++){printf("\n %s",tmatrix[j]);} //k3=max data read
  3. 0.5
  4. 0.2
  5. 0.3
  6. 0.6

Now I need to convert the content of tmatrix[][] into a float array
so that float_array[1]=0.5
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: converting string[][] to float[]

 
-1
  #2
Oct 24th, 2007
No problem -- just call atof()
  1. float n = atof(tmatrix[i]);

Not a perfrect solution, but works ok for most purposes.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 41
Reputation: mank is an unknown quantity at this point 
Solved Threads: 0
mank mank is offline Offline
Light Poster

Re: converting string[][] to float[]

 
0
  #3
Oct 24th, 2007
Thanks a lot
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: converting string[][] to float[]

 
1
  #4
Oct 25th, 2007
strtod() would be a better function to use, because it has better error diagnostics.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC