This works for me
int main()
{
char Seg_String[] = "2000;ON_0;1000;ON_2";
char* ptr = strtok(Seg_String,";");
while(ptr)
{
printf("%s\n",ptr);
ptr = strtok(NULL, ";");
}
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
print out the value of the string before entering that loop so that you can verify it is correct or not.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>Seq_String=strcat(&String_received,&Single_Char);
That is a huge problem. String_received is already a pointer, and you are passing a pointer to a pointer, which is wrong. Also, if [b]Single_Char[b] is what that name implies (defined as char and not char*) then you can't use strcat() with it because strcat() expects a null-terminated array of characters.
Third: what is Seq_String? you don't need it because after strcat() is done String_received will contain the entire new string. All strcat() does is return either String_received or NULL, depending on error or not.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
maybe something like this, which will leave String_received untouched. This allocates new memory for Seg_string, so don't forget to free() it sometime later after you are done with it.
char* Seg_string = 0;
char* Single_Char = Get_Char_pc();
Seg_string = malloc(strlen(String_received) + strlen(Single_Char) + 1);
strcpy(Seg_string, String_received);
strcat(Seg_string, Single_Char);
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343