PDA

View Full Version : Convert String


fbitonti
01-31-2007, 02:52 AM
Can some one tell me how to convert a string to a float?

$exampleFileName = ( "C:\\2dTrussMaterials.txt" );
float $i;
int $j=0;
// Now read it back one line at a time
//
$fileId=`fopen $exampleFileName "r"`;
string $nextLine = `fgetline $fileId`;
while ( size( $nextLine ) > 0 ) {
print ( $nextLine );
$i = $nextLine;
$nextLine = `fgetline $fileId`;
$j=$j+1;
}
fclose $fileId;

I am trying to store the string $nextLine in the float $i.

this is the error i get.

// Error: float $i;
//
// Error: Invalid redeclaration of variable "$i" as a different type. //
// Error: $i = $nextLine;
//
// Error: Cannot cast data of type string to int[]. //

Thanks for the help

fbitonti
01-31-2007, 03:02 AM
i forgot to initilize the float.


$exampleFileName = ( "C:\\2dTrussMaterials.txt" );
float $i=0.0;
int $j=0;
// Now read it back one line at a time
//
$fileId=`fopen $exampleFileName "r"`;
string $nextLine = `fgetline $fileId`;
while ( size( $nextLine ) > 0 ) {
print ( $nextLine );
$i = $nextLine;
$nextLine = `fgetline $fileId`;
$j=$j+1;
}
fclose $fileId;

CGTalk Moderation
01-31-2007, 03:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.