NEED TO FIX: updated some code, but it still retrieves wrong message length
This commit is contained in:
@@ -44,20 +44,30 @@ char* fetch_message_string(char* message) {
|
|||||||
}
|
}
|
||||||
int end_index = end - message;
|
int end_index = end - message;
|
||||||
|
|
||||||
if (*(message+ end_index-2) = '\r') {
|
if (*(message + end_index-2) = '\r') {
|
||||||
num_of_terminators = 2;
|
num_of_terminators = 2;
|
||||||
} else {
|
} else {
|
||||||
num_of_terminators = 1;
|
num_of_terminators = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_length = end_index - start_index;
|
end_index -= num_of_terminators;
|
||||||
char* message_string = malloc(message_length + 1);
|
|
||||||
|
|
||||||
for (int i=0;i < message_length-num_of_terminators; i++) { /* The reason the upper-bound is message_length-1 is because the last
|
int message_length = end_index - start_index;
|
||||||
|
char* message_string = malloc(message_length + 2);
|
||||||
|
|
||||||
|
printf("Message length is %d\n",message_length);
|
||||||
|
|
||||||
|
for (int i=0; i<message_length; i++) { /* The reason the upper-bound is message_length-1 is because the last
|
||||||
character is a new-line, which the user would not have typed. */
|
character is a new-line, which the user would not have typed. */
|
||||||
|
|
||||||
*(message_string + i) = *(message + start_index + i);
|
*(message_string + i) = *(message + start_index + i);
|
||||||
|
printf("%c",*(message_string + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
*(message_string + (message_length - num_of_terminators)) = '\0';
|
strcat(message_string,"\0");
|
||||||
|
|
||||||
|
// printf("%s\n",message_string);
|
||||||
|
|
||||||
|
// *(message_string + (message_length - num_of_terminators)) = '\0';
|
||||||
return message_string;
|
return message_string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user