diff --git a/BlogDB.c b/BlogDB.c index 6a2858c..36bbf86 100755 --- a/BlogDB.c +++ b/BlogDB.c @@ -1,6 +1,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -214,6 +215,19 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con) // Get first line fgets(Buffer, BufferLength, FilePointer); + // Get the substrings Buffer[0:3] and Buffer[-6:-1] + // Buffer[BufferLength] is the same as "\0" but without warnings + int LineLength = strlen(Buffer); + char startTest[5] = {Buffer[0], Buffer[1], Buffer[2], Buffer[3], Buffer[BufferLength]}; + char endTest[6] = {Buffer[LineLength - 6], Buffer[LineLength - 5], Buffer[LineLength - 4], Buffer[LineLength - 3], Buffer[LineLength - 2], Buffer[BufferLength]}; + + // Check that the firstline starts with "

" and ends with "

" + if (!(strcmp(startTest, "

") == 0 && strcmp(endTest, "

") == 0)) { + printf("%s What is this %s\n", startTest, endTest); + return -1; + } + + // This is equivalent to Buffer = Buffer[3:-6] // This is done to remove the

tags for (int i = 4; i < BufferLength; ++i) { @@ -957,8 +971,8 @@ int main(int argc, char *argv[]) //TogglePost(81, con); //printf("%s\n", IsEnabled(81, con) ? "True" : "False"); //AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con); - BlogWrite(con); - + //BlogWrite(con); + // ================================= exit(0);