No, you have to use the sprintf (better use snprintf) approach. "some static text"+3 just increases the address returned by the string literal by 3 bytes, which would actually pass "e static text" to your function.


Sebastian Schmidt
Abteilung Anwendungsentwicklung

HUK-COBURG
Bahnhofsplatz
96444 Coburg
Telefon 09561 96-2391
Telefax 09561 96-3602
E-Mail Sebastian.Schmidt@xxxxxxxxxxxxx
Internet www.HUK.de
=============================================================
HUK-COBURG Haftpflicht-Unterstützungs-Kasse kraftfahrender Beamter Deutschlands a. G. in Coburg
Reg.-Gericht Coburg HRB 100; St.-Nr. 9212/101/00021
Sitz der Gesellschaft: Bahnhofsplatz, 96444 Coburg
Vorsitzender des Aufsichtsrats: Werner Strohmayr.
Vorstand: Rolf-Peter Hoenen (Sprecher), Wolfgang Flaßhoff, Stefan Gronbach, Klaus-Jürgen Heitmann, Christian Hofer, Dr. Wolfgang Weiler.
=============================================================



-----Ursprüngliche Nachricht-----
Von: c400-l-bounces+sebastian.schmidt=huk-coburg.de@xxxxxxxxxxxx [mailto:c400-l-bounces+sebastian.schmidt=huk-coburg.de@xxxxxxxxxxxx] Im Auftrag von Lim Hock-Chai
Gesendet: Donnerstag, 12. Juni 2008 16:59
An: C programming iSeries / AS400
Betreff: Re: [C400-L] basic c question about char *

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 ...

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].