Article View: alt.comp.lang.learn.c-c++
Article #33Re: Return a string in C???
From: chris
Date: Mon, 02 Jun 2003 17:42
Date: Mon, 02 Jun 2003 17:42
27 lines
1746 bytes
1746 bytes
"R" <R@R.R> wrote in message news:<oVDAa.85219$Vi5.2444320@news1.calgary.shaw.ca>...
> Hey all!
>
> Just learning C and I'm wondering how one would return a string from a
> function.
>
> Basically, I'm passing in a float and returning a 1-3 character string based
> on the value of the float.
>
> Is there a simple example that someone can provide?
>
> Thanks!
>
> P.s. Searching for "C" in Google and groups is a pain! : )
you could have the function allocate the buffer and return the length:
int StringFunction (char ** buffer) {
int bufferSize;
...
*buffer = (char *)malloc(bufferSize);
...
return bufferSize;
}
chris
Technical Details
Message-ID:
<b709e49a.0306020942.3b31389d@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mailReferences:
<oVDAa.85219$Vi5.2444320@news1.calgary.shaw.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114592,726fa50532a809c2 X-Google-Attributes: gid114592,public X-Google-Thread: 1014db,726fa50532a809c2 X-Google-Attributes: gid1014db,public X-Google-Thread: 10d4ba,726fa50532a809c2 X-Google-Attributes: gid10d4ba,public X-Google-ArrivalTime: 2003-06-02 10:42:57 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mail From: ChrisCummings@hot.rr.com (chris) Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c Subject: Re: Return a string in C??? Date: 2 Jun 2003 10:42:56 -0700 Organization: http://groups.google.com/ Lines: 27 Message-ID: <b709e49a.0306020942.3b31389d@posting.google.com> References: <oVDAa.85219$Vi5.2444320@news1.calgary.shaw.ca> NNTP-Posting-Host: 24.162.154.83 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1054575776 19957 127.0.0.1 (2 Jun 2003 17:42:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 2 Jun 2003 17:42:56 GMT