The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Initialisation of arrays

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
greadey Posted - 02/17/2005 : 09:57:09 AM
Greetings everyone,

I am trying to initialise an array of strings - the following syntax compiles;

string channels[4] = {"str1", "str2", "str3", "str4"};

when I try to print the array using;


for(int num = 0; num <= 3; num++) {
printf("Channel[%i]: %s\n", num, channels[num]);
}


All I get is;
Channel[0]:
Channel[1]:
Channel[2]:
Channel[3]:

In other words the array has not been initialised.

Is this a problem with Origin C?

Ver 7.5 SR3
Win XP Pro
2   L A T E S T    R E P L I E S    (Newest First)
greadey Posted - 02/17/2005 : 10:57:58 AM
Thanks for that - I didn't think of using a vector.
cpyang Posted - 02/17/2005 : 10:36:14 AM
Origin C supports vector, so array usage might be not well tested and thus more likely to have bugs,

Try the following instead,




vector<string> channels = {"str1", "str2", "str3", "str4"};
for(int num = 0; num < channels.GetSize(); num++)
{
printf("Channel[%i]: %s\n", num, channels[num]);
}





I tested in Origin75 SR5 and sure enough, there was a bug with string array initialization. I tried in our in house current code build and problem seemd fixed, so in future release, this bug should be gone. But in general, it is much better to use vectors in Origin C.


CP



Edited by - cpyang on 02/17/2005 10:41:40 AM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000