I am getting these unexpected chars when I try to print the string inside of a file. How can I deal with this situation?
This is my code:
#include <stdlib.h>
#include <stdio.h>
char *readFile(char *filename)
{
char * buffer;
long length;
FILE * f = fopen (filename, "r");
if (f)
{
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc (length);
if (buffer)
{
fread (buffer, 1, length, f);
}
fclose (f);
}
return buffer;
}
int main() {
char *firstS = readFile("file.txt");
printf("%s \n", firstS);
return 0;
}