I think I almost got it but I have a small glitch in my program.
Code:
int main(){
char *sentences = convToChar("tfile.txt", 96, 15);
printf("%s", sentences);
return 0;
}
char *convToChar(const char *file_path, unsigned int char_length, unsigned int line_length){
FILE *file;
char f_text[char_length + 1];
//char text[char_length + 1];
char *text = malloc(sizeof(char) * (char_length + 1));
file = fopen(file_path, "r");
for(unsigned int i = 0; i < line_length; i++){
fgets(f_text, char_length + 1, file);
strcat(text, f_text);
}
fclose(file);
return text;
}
When I run this program, it prints out my text file but with the weird symbols like below.
"╪%UHello!"
But when I use printf("%s", text); in my convToChar,
Code:
//stuffs
//stuffs
fclose(file);
printf("%s", text);
return text;
}
This prints out the actual text file...
So I think there's something wrong in the main,
Code:
char *sentences = convToChar("tfile.txt", 96, 15);
printf("%s", sentences);
Am I doing something wrong?