1 registered members (7th_zorro),
429
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
String help
#440283
04/22/14 16:16
04/22/14 16:16
|
Joined: Jun 2013
Posts: 1,609
DdlV
OP
Serious User
|
OP
Serious User
Joined: Jun 2013
Posts: 1,609
|
Hi all. There must be something obviously wrong with this snipit, but I can't see it. Why is the value of s1 being reset after the last assignment to its value from the prior bar? Thanks.
function run() {
set(LOGFILE);
if (Bar>5) quit();
string s1 = "12345678901234567890";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "00";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "xx";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "**";
printf("\nBar,s1=%i,%s",Bar,s1);
sprintf(s1,"%02d",3*Bar+7);
printf("\nBar,s1=%i,%s",Bar,s1);
}
|
|
|
Re: String help
[Re: jcl]
#440316
04/23/14 13:47
04/23/14 13:47
|
Joined: Jun 2013
Posts: 1,609
DdlV
OP
Serious User
|
OP
Serious User
Joined: Jun 2013
Posts: 1,609
|
Thanks jcl. I understand that "**" is a string constant and s1 is being set to the address of it. (Although anytime one has available the address of something, it's a bit difficult to really call it a "constant". ) But "____________________" is also a string constant so I don't quite see the difference since I didn't sprintf more than 2 bytes in... In any case, I have added your s1 initialization into the code with an additional printf, but the problem persists. After the 1st iteration where the printf displays your initialization string as above, on every subsequent bar your initialization string is not present. In every subsequent bar, s1 reverts to its ending value on the prior bar. Why? Thanks.
function run() {
set(LOGFILE);
if (Bar>5) quit();
string s1 = "12345678901234567890";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "00";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "xx";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "**";
printf("\nBar,s1=%i,%s",Bar,s1);
s1 = "____________________";
printf("\nBar,s1=%i,%s",Bar,s1);
sprintf(s1,"%02d",3*Bar+7);
printf("\nBar,s1=%i,%s",Bar,s1);
}
|
|
|
Re: String help
[Re: jcl]
#440323
04/23/14 16:10
04/23/14 16:10
|
Joined: Jun 2013
Posts: 1,609
DdlV
OP
Serious User
|
OP
Serious User
Joined: Jun 2013
Posts: 1,609
|
Thanks jcl (& Petra). The paradigm has finally shifted. It's a lousy paradigm, but it is what it is. Thanks.
|
|
|
|