Need help with string and array

The result from running my code is perfect but I don't understand why this happened all the time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  #define RANGE 33

char S[RANGE]={' ',' ','T','H','E',' ','C','A','T',' ','C','H','A','S','E',' ','T','H','E',' ',' ',' ','M','O','U','S','E',' ',' ',' ','\0'};

char T[RANGE];

int main ()
{
    int i=0,j=0,k=0;

while (S[i] == ' ') i++;

while (S[j] != '\0')
{

    while (S[i] != ' ')
    {
        T[k] = S[i];
        i++;
        k++;
    }

    while (S[i] == ' ' && S[i+1] != ' ')
    {
        T[k] = S[i];
        i++;
        k++;
    }

    while (S[i] == ' ' && S[i+1] == ' ')
    {
        i++;
    }

    j++;
}

    printf ("%s",T);

    return 0;
}


In the end, it does not end with "return 0" but an error instead.
What error are you getting?
Topic archived. No new replies allowed.