• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Parsing cString - Silly question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Parsing cString - Silly question (From: Lorenzo <email@hidden>)

  • Prev by Date: Incompatible types in Currency Converter tutorial
  • Next by Date: Re: Encrypt a string
  • Previous by thread: Re: Parsing cString - Silly question
  • Next by thread: Using keyboard to toggle checkboxes in NSTableView cell
  • Index(es):
    • Date
    • Thread