Hello,
I am completely new to C programming. Below code is that I gathered from Google searches and maybe incorrect.
I am trying to code a function which will read a file on system and return its content back as string. Code is below.
Code:char * readtxt(){ FILE * fptr; char c; static char txt[30]; int len=0; fptr = fopen("C:\\Users\\Test\\Desktop\\Dev\\test.txt", "r"); while(1){ c = fgetc(fptr); if(c!= EOF) { txt[len]=c; len++; } else break; } fclose(fptr); return txt; }
I suppose txt variable is pointer. But I need to return the file content as string so the function structure should look like
Code:returnType function(){ return "File Contents as String"; }
How can I achieve this please?
Cheers