# Thread: Can someone solve this problem for me?

1. ## Can someone solve this problem for me?

Im trying to break a string into arrays of pairs... But the thing is an error will occur when this code is executed.

Code:
```void letterPair(char str[])
{
int i;
int j;
int total = 0;
char temp[50][50];
char abc[1];

for(i = 0; str[i] != '\0'; i++)
{
if(!isspace(str[i]) )
{
if(!isspace(str[i+1]) )
{
if( str[i+1] != '\0' )
{
abc[0] = str[i];
abc[1] = str[i+1];
strcat(temp[total],abc);
total++;
}
}
}
}
}```
Lets say my str = "THIS IS A STRING"
I want to break it up to "TH" "HI" "IS" "IS" "ST" "TR" "RI" "IN" "NG"
And im leaving out the pairs which have spaces. Eg " I" "S " " A" "A " and " S". (Pls note the spaces)

Or are there any other ways to join two characters together??Help is very much appreciated!! Thanks a lot!!

2. Code:
`char abc[1];`
This only holds 1 character. In order to hold the 2 characters you require, and the NULL terminator which is needed when using any of the string functions, this array must hold at least 3 characters. Your use of strcat is also inappropriate here, the strcpy function would be a better choice. A simpler set of loop and conditional statements should be:

Code:
```for( i = 0; str[i]; ++i )
if( !isspace(str[i]) && !isspace(str[i+1]) && str[i+1] )
{
// Copy two characters starting at str[i] into your array
}```

3. I see!!! Thanks a lot for helping me out!! Really appreciate it!! Had no one to turn to with my C programming...Again, thank you very much!! ^^