DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   converting string[][] to float[] (http://www.daniweb.com/forums/thread94191.html)

mank Oct 24th, 2007 6:56 pm
converting string[][] to float[]
 
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
char tmatrix[10][100];
for(j=0;j<k3;j++){printf("\n %s",tmatrix[j]);}  //k3=max data read
 0.5
 0.2
 0.3
 0.6

Now I need to convert the content of tmatrix[][] into a float array
so that float_array[1]=0.5

Ancient Dragon Oct 24th, 2007 7:28 pm
Re: converting string[][] to float[]
 
No problem -- just call atof()
float n = atof(tmatrix[i]);

Not a perfrect solution, but works ok for most purposes.

mank Oct 24th, 2007 7:42 pm
Re: converting string[][] to float[]
 
Thanks a lot :D

Salem Oct 25th, 2007 7:49 am
Re: converting string[][] to float[]
 
strtod() would be a better function to use, because it has better error diagnostics.


All times are GMT -4. The time now is 4:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC