Skip to content
WJunction - Webmaster Forum

[C] Get array from Function

Status
Not open for further replies.
Hi,

I'm new with C and I can't solve one simple problem.

I read 1 file with that function:


PHP:
char* readFileBytes(const char *name)  {  
    FILE *fl = fopen(name, "r");  
    fseek(fl, 0, SEEK_END);  
    long len = ftell(fl);  
    char *ret = malloc(len);  
    fseek(fl, 0, SEEK_SET);  
    fread(ret, 1, len, fl);  
    fclose(fl);  
    return ret;  
}



and it return ret, the content of file; for example:

Code:
abc
def
...
aaa

and if I simply add to main this command:

PHP:
int main() { 

printf("%s\n",readFileBytes("lista.txt") );

}

I get printed all the content of file.

Now I need to pass that content in main, but I can't find how: I need to work on line of file's content, one by one.

Can anyone help me to put the content of readFileBytes into an array on main function?


Thanks
 
Last edited:
Status
Not open for further replies.

About the author

S
Active Member · Joined
741
Messages
59
Reactions
28
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom