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.
Expand|Select|Wrap|Line Numbers
- 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;
- }
Expand|Select|Wrap|Line Numbers
- returnType function(){
- return "File Contents as String";
- }
Cheers