RE: [Dev-C++] passing the content of a string to a variable from
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@at...> - 2003-04-09 04:00:54
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of jose isaias cabrera
> Sent: Wednesday, April 09, 2003 4:52 AM
> To: dev...@li...
> Subject: [Dev-C++] passing the content of a string to a variable from
>
>
>
> Greetings O SmartOnes!
>
> I have the following c code:
>
> char FileContent(char *file)
> {
> char fcontent(3000);
> ...
> /*in here I grab the content of a text file */
> ...
> return(fcontent);
> }
I assume C:
>
> int main(int argc, char *argv[])
> {
> char text[3000];
> ...
> ...
> ...
> text = FileContent("temp.txt");
FileContent returns a char. You assign it to an array which is not proper.
If you intend it to return a char, you have to do something like:
text[0]=FileContent("temp.txt");
If you made a mistake and intend to return a char * you have either to do:
char *text;
/* ... */
text=FileContent("temp.txt");
or
char text[3000];
char *p;
/* ... */
p=FileContent("temp.txt");
strncpy(text, p, 3000);
text[2999]='\0';
> }
>
> I can't get this to work. I've a bunch of places and I even
> tried to get
> the pointers to no avail. I am new to c, but I am an expert
> programmer.
> Any c help will be greatly appreciated.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|