Hi,
I'm new with C and I can't solve one simple problem.
I read 1 file with that function:
and it return ret, the content of file; for example:
and if I simply add to main this command:
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
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: