Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mixing char in

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
greetings all...

I have the following declarations
char *msg[] = {"Hello world..."};
long year = 2002;
and want to have

*msg = "Hello world 2002...";
how do I do it? mixing char and long?


really can't understand this one =( My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
sprintf(&msg[strlen(msg)-3]," %d%s", year,"...");
 
Just my 2 cents... the above should work fine. But also look into

char buffer[128];
sprintf(buffer,"Hello World %d...",2002);

Matt

 
thanks =) after some consulting by others i decided to change my declaration to
char[100] = {"hello world...\n\0"};
cause char *msg wouldn't work =((

anyhow thanks =) My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
If you really want the "long" mixed in...

...
char buf[128];
long year = 2002L;

sprinf(buf, "Hello World %ld\n", year);

...subtle difference :)

 
What I meant was that those two options worked, but NOT when I used
char *msg; only when I used char msg[100];.... My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Right... i didnt notice it before but you can do it with char* msg because you really dont have any space allocated. Also the above when you say

char msg[] = "hello world...";

would not work eaither because only enough space is allocated for "hello world..."

Matt
 
oki, then I understand =)

Thanks Zyrenthian... My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top