Csound Csound-dev Csound-tekno Search About

[Csnd] Assingning the content of a variable to a string

Date2013-07-03 15:41
FromJan Jacob Hofmann
Subject[Csnd] Assingning the content of a variable to a string
Dear list,

I am just having for the first time a closer look at strings.  I do  
wonder if there is a more elegant way of assigning the content of an i- 
time variable to a string than this one:

Sinstance 	sprintf		"%i", gi_instance				; convert instance ID to a  
string

I did use that one, which finally worked fine. However it does not  
seem like an elegant way as it took me a while to find the right  
formatting. All in all I wonder if it is just a kind of work-around,  
which I came across, missing the right way of assigning. However I  
tried:
Sinstance	strcpy		gi_instance

which was easier to use but just created an empty string. So is  
sprintf really the best way to do it?

All the best,

Jan Jacob



sound         |         movement          |          object          
|          space
sonic architecture       |        site: http://www.sonicarchitecture.de
spatial electronic composition  |  higher order ambisonic music


Date2013-07-03 20:42
Fromjoachim heintz
SubjectRe: [Csnd] Assingning the content of a variable to a string
hi jan jacob -

yes, i think it's the correct way of doing it. if you need some 
information for the possible formatting options, have a look at the 
manual page for printf (example printf2.csd).

for converting a string to a number, you can use strtod.

best -

	joachim



Am 03.07.2013 16:41, schrieb Jan Jacob Hofmann:
> Dear list,
>
> I am just having for the first time a closer look at strings.  I do
> wonder if there is a more elegant way of assigning the content of an
> i-time variable to a string than this one:
>
> Sinstance     sprintf        "%i", gi_instance                ; convert
> instance ID to a string
>
> I did use that one, which finally worked fine. However it does not seem
> like an elegant way as it took me a while to find the right formatting.
> All in all I wonder if it is just a kind of work-around, which I came
> across, missing the right way of assigning. However I tried:
> Sinstance    strcpy        gi_instance
>
> which was easier to use but just created an empty string. So is sprintf
> really the best way to do it?
>
> All the best,
>
> Jan Jacob
>
>
>
> sound         |         movement          |          object
> |          space
> sonic architecture       |        site: http://www.sonicarchitecture.de
> spatial electronic composition  |  higher order ambisonic music
>
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>