Thank you for all the reply. Now I've a better understanding of char *.


One more question:

Void myFunction(char *message)

myFunction("my static message");

// above function call is pretty straight forward. But what if I need
to pass non static message to it? Is there a way to do it without
having to create a char * or char [] variable. Something like this (I
know the syntax is not correct):

myFunction("my static message" + myInt);


Or do I have to do

char myMessage[20];
sprintf(myMessage, "my non Static message %i", myInt);
myFunction(myMessage);




-----Original Message-----
From: c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx
[mailto:c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx] On
Behalf Of Lim Hock-Chai
Sent: Wednesday, June 11, 2008 4:36 PM
To: C programming iSeries / AS400
Subject: [C400-L] basic c question about char *

can somebody help me understand how char * work?

char * s1;
s1 = "assign a value";
s1 = "assign another value"; //does c auto deallocate storage and
reallocate a longer one for this assignment?

. . .



char * s1
int myInt = 10;

sprintf(s1, "test %i", myInt); //why is s1 contains *null after this
assignment?




--
This is the C programming iSeries / AS400 (C400-L) mailing list To post
a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.


This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact [javascript protected email address].