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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Initialisation of arrays
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

greadey

UK
Posts

Posted - 02/17/2005 :  09:57:09 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

cpyang

USA
1406 Posts

Posted - 02/17/2005 :  10:36:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

greadey

UK
Posts

Posted - 02/17/2005 :  10:57:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for that - I didn't think of using a vector.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000