#include #include "message_helpers.h" char* fetch_from_string(char* message, char* indicator) { char* message_copy = malloc(strlen(message)); strcpy(message_copy,message); char* token = malloc (sizeof(char) * strlen(message_copy)); char* string_to_search = malloc(strlen(indicator) + 1); strcpy(string_to_search,indicator); strcat(string_to_search,":"); token = strtok(message_copy," r\n"); while (strcmp(token,string_to_search) != 0) { token = strtok(NULL," \r\n"); if (token == NULL) { return NULL; } } token = strtok(NULL," \r\n"); return token; } char* fetch_message_string(char* message) { char* message_copy = malloc(strlen(message)); strcpy(message_copy,message); int num_of_terminators = 0; int start_index = 0; int end_index = 0; int message_length = 0; char* start = strstr(message_copy,"START_OF_MESSAGE"); if (start == NULL) { return NULL; } start_index = start - message_copy; start_index += strlen("START_OF_MESSAGE"); while (*(message_copy + start_index) == '\n' || *(message_copy + start_index) == '\r') { start_index++; } char* end = strstr(message_copy,"END_OF_MESSAGE"); if (end == NULL) { return NULL; } end_index = end - message_copy; if (*(message_copy + end_index-2) == '\r') { num_of_terminators = 2; } else { num_of_terminators = 1; } end_index -= num_of_terminators; message_length = end_index - start_index; char* message_string = malloc(message_length + 2); printf("Message goes from %d to %d\n",start_index,end_index); for (int i=0; i