Fixed the bug. It will now return the full string.
This commit is contained in:
parent
171195fbd6
commit
3d63b6ef4b
@ -1,12 +1,16 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "../include/fileReader.h"
|
#include "../include/fileReader.h"
|
||||||
|
|
||||||
char *ReadHTML(char path[]) {
|
char *ReadHTML(char path[]) {
|
||||||
FILE *file_ptr = fopen(path, "r");
|
FILE *file_ptr = fopen(path, "r");
|
||||||
char file[GetFilesize(file_ptr)];
|
|
||||||
char ch;
|
int fileSize = GetFilesize(file_ptr);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
char *file = malloc(fileSize + 1);
|
||||||
|
char ch;
|
||||||
|
|
||||||
if (NULL == file_ptr) {
|
if (NULL == file_ptr) {
|
||||||
printf("File can't be opened \n");
|
printf("File can't be opened \n");
|
||||||
}
|
}
|
||||||
@ -16,6 +20,8 @@ char *ReadHTML(char path[]) {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file[i] = '\0';
|
||||||
|
|
||||||
fclose(file_ptr);
|
fclose(file_ptr);
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
|
@ -3,5 +3,5 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char *file = ReadHTML("/home/skingging/Documents/Projects/C/C-Webserver/HTML/index.html");
|
char *file = ReadHTML("/home/skingging/Documents/Projects/C/C-Webserver/HTML/index.html");
|
||||||
printf("Size: %d", sizeof(file));
|
printf(file);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user