Skip to content
WJunction - Webmaster Forum

[C] Get array from Function

Status
Not open for further replies.

skinner

Experienced Member
741
2010
59
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
Experienced Member · Joined
741
Messages
59
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom