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
 array of string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

mletzgus

Germany
Posts

Posted - 10/31/2003 :  06:45:40 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,


what's wrong here:

const string Units[5]={"psek", "nsek", "musek", "msek", "sek"};

printf("%s\n", Units[1]);

Output is just the '\n', no "nsek".


thx,
michael

cpyang

USA
1406 Posts

Posted - 10/31/2003 :  08:54:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It seems that there is a bug with string array initialization. We don't recommand using string in a C array as Origin C has vector which suports string and vector is more reliable, and has basic support like GetSize(),

Try this


const vector<string> Units={"psek", "nsek", "musek", "msek", "sek"};
printf("%s\n", Units[1]);
printf("3rd char is %c\n", Units[1][2]);



As for the array initialization bug, I have added a tracker 5457
CP




Edited by - cpyang on 10/31/2003 08:56:49 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 10/31/2003 :  09:16:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CP,

StringArray seems to work.

const StringArray saUnits = {"psek", "nsek", "musek", "msek", "sek"};
printf("%s\n", saUnits[1]);
printf("size=%d\n",saUnits.GetSize());

Is there a reason not to use that?

Mike Buess
Origin WebRing Member
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 10/31/2003 :  09:40:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

in <string.h>

typedef vector<string> StringArray;

so they are the same thing. I prefer using vector<string> just to be more accurate.

CP




Edited by - cpyang on 10/31/2003 09:40:41 AM
Go to Top of Page

mletzgus

Germany
Posts

Posted - 11/01/2003 :  04:02:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi all,

i'm "native" C/C++ coder - so I tried to keep code as clean and "C-like" as possible.

But the StringArrays/vectors work very well. Thanks :-)

by,
Michael
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