I've made this rather messy method that is supposed to split the message parameter (max 160 byte) into 60-byte strings if it is larger than 60 bytes. The message is always between quotes so I also want to ignore them and just get whats between the quotes.
Example: "Hi there everybody" //I want Hi there everybody
The problem with this method is when the printf at the end is executed it doesn't output what it's supposed to.
With the message "Hello everybody" the output is:
tempString =
tempString2 =
tempString 3 = u
I bet it's just a silly stupid mistake, but I just can't figure out whats wrong.
void saveMessage(char *message) {
int i = 1; //1 to skip the first "
int isToManyCharacters = 0;
int currentTempString = 1;
char tempString1[60];
char tempString2[60];
char tempString3[60];
while (message[i] != '"') {
//If under 60 byte fill up tempString1
if(i<60) {
tempString1[i] = message[i];
printf("command:61 tempString1[i] = %c message[i] = %c\n", tempString1[i], message[i]);
if (i+1 == 60) {
tempString1[i+1] = '\0';
currentTempString++;
}
}
//If over 60 bytes but under 120 fill up tempString2
else if(i==60 || i<120) {
tempString2[i-60] = message[i];
if (i+1 == 120) {
tempString2[i+1] = '\0';
currentTempString++;
}
}
//If over 120 bytes but under 160 fill up tempString3
else if(i==120 || i<160) {
tempString2[i-60] = message[i];
if (i+1 == 160) {
tempString2[i+1] = '\0';
isToManyCharacters = 1;
}
}
i++;
}
//Adding the 0-byte
if (currentTempString == 1)
tempString1[i] = '\0';
else if (currentTempString == 2)
tempString2[i] = '\0';
else if (currentTempString == 3)
tempString3[i] = '\0';
printf("tempString = %s\ntempString2 = %s\ntempString 3 = %s\n",tempString1, tempString2, tempString3);
}