Re: Parsing cString - Silly question
Re: Parsing cString - Silly question
- Subject: Re: Parsing cString - Silly question
- From: John Stiles <email@hidden>
- Date: Fri, 18 Nov 2005 10:38:50 -0800
The straight C++ way is vector<float>. Use it like so:
vector<float> array;
for( ;; )
{
float value;
if( 1 != fscanf( file, "%f", &value ) )
break;
array.push_back( value );
}
printf( "Array has %d elements. Item 0 is %f.\n", array.size(), array
[0] );
You can also do it with NSMutableArray or CFMutableArray; in that
case you have to make NSNumbers of CFNumbers which is a bit of an
extra step. The code basically flows the same so I'll leave that to you.
On Nov 18, 2005, at 7:13 AM, Lorenzo wrote:
Hi,
how can I add an element to an array of float?
I am parsing a text file contains variables, but until I parse the
whole
text I cannot know how many variables that text contains.
Actually I parse the text twice. The first time I count the
variables then
float *variables = malloc(sizeof(float) * totVar);
then I parse the text again to put the variables into my array.
Is a way to do everything in one loop only? Will be faster?
Sorry for the silly question.
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden