954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

mank
Light Poster
41 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

No problem -- just call atof()

float n = atof(tmatrix[i]);


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

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Thanks a lot :D

mank
Light Poster
41 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

strtod() would be a better function to use, because it has better error diagnostics.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You