Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic String Array Size

Status
Not open for further replies.

moonoo

Programmer
May 17, 2000
62
US
Hi ,
I have a string array defined in the main function..
I am passing the array to a function and trying to
iterate the array . My code is something like this
inside main
string tradeId[8] = { "?" , "299339Z","299323Z","301537Z","348123Z","301545Z","301535Z","347597Z"};

and inside some function i am iterating the array as
for(int arrcnt = 0 ; glbDealid[arrcnt] !='/0' ; arrcnt++)
{
cout<<glbDealid[arrcnt];

}
But it is giving core dump error . Just wanted to check whether there is some other way of finding out the array length in C++..
Regards'
Dev
 
what is glbDealid?

Ion Filipski
1c.bmp
 
It is the same array in the other function ..
I am passing the Tradid array to that function and collecting it in glbDealid array
 
If you use the string &quot;0&quot; to look for the end of strings table, your sode should look a bit like this:

string tradeId[8] = { &quot;?&quot; , &quot;299339Z&quot;,&quot;299323Z&quot;,&quot;301537Z&quot;,&quot;348123Z&quot;,&quot;301545Z&quot;,&quot;301535Z&quot;,&quot;347597Z&quot;, &quot;0&quot;};
.....

for(int arrcnt = 0 ; !strcmp(glbDealid[arrcnt], &quot;0&quot;) ; arrcnt++)
{
cout<< glbDealid[arrcnt];

}

Ion Filipski
1c.bmp
 
for(int arrcnt = 0 ; glbDealid[arrcnt] !='/0' ; arrcnt++)
{
cout<<glbDealid[arrcnt];

}


Change glbDealid[arrcnt] !='/0' To

glbDealid[arrcnt-1] != '/0'

 
1. great '/0' quicksaab. What do you think about '\0'?
2. '\0' is a single character, but &quot;0&quot; is a string. As far as I see above glbDealid is an array of strings, not of characters [LOL]

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top