Making minimal changes this is a working version of your code:
#include <string.h>
#include <stdio.h>
int main()
{
char current[2] = { 0x0, 0x0 }; // Will be null terminated
char chs[100] = "Hello World";
char token[100] ;
int pos = -1; // Destination of strcat must also be null terminated
token[0] = '\0' ;
// String literals does not actually have " in memory they end in \0
while((current[0] = chs[++pos]) != '\0')
{
strcat(token, ¤t[0]); // Take the address of the first char in current
}
printf("%s\n", token ) ;
return 0 ;
}
strcat
expects both the source and destination to be null terminated strings. In your case it looks like current
just ended up having a \001
followed by a null terminator after it in memory.