- Joined
- Dec 22, 2023
- Messages
- 34
- Reaction score
- 5
i am rather new to c,and im trying to create a function that open a file,read a line,and return that line,but,on the part that open the file,it returns a warning,but if i take the same code and put directly into "int main()',it works,but then the function doesnt work,it returns null here is the code
C:
#include <stdio.h>
#include <stdlib.h>
/*
* todo can be ->
* 1 -> read
* 2 -> wright
* 3 -> overwright
* WILL ADD MORE
*/
/*
* mode can be ->
* 0 -> none of the below
* 1 -> read all lines
* 2 -> read one line
* WILL ADD MORE
*/
char *open_readF(char *filepath,const int mode,const int todo){
FILE *file = fopen(filepath,"r");
char result[100];
fgets(result, 100, file);
return result;
}
int main(){
/*
here is the code that works,its the same,but it works somehow
*/
FILE *file = fopen("addons.c","r");
char result[100];
fgets(result, 100, file);
printf("CODE STRIPED FROM FUNCTION ->%s\n",result);
char *var = open_readF("addons.c",0,1);
printf("FUNCTION ->%s\n",var);
return 0;
}