[Solved] Spaces not being replaced with newlines


Welcome to C! You have allocated no memory so you error. Use malloc to allocate the memory. I have made this code that works for you:

void f(char*s,char*toString)
{
    char c,i=0,j=0;
    int num=0;
    while(c=*(s++))
        { 

            toString[num]=c; 
          //  putchar(c);
            if(c==' ')++i;
            if((j<4&&i==7)||(j>=4&&i==6))
                {
                    i=0;
                    ++j;
                    toString[num]='\n';
                   // putchar('\n');

                } 
                num++;
        }
}

state_t initial_user_state_to_c(char * string)
{
    char * sting;
    sting = malloc(200);
    state_t ret;
    int s,c;
    char * str;
    str = string;
    card_t card;
    state_init(&ret);
    f(str,sting);
    str = sting;
    for(s=0;s<8;s++)
    {
        /* Move to the next stack */
        if (s!=0)
        {
            while((*str) != '\n')
            {
                str++;
            }
            str++;
        }


        for(c=0;;c++)
        {
            /* Move to the next card */
            if (c!=0)
            {
                while(((*str) != ' ') && ((*str) != '\n'))
                {
                    str++;
                }
                if (*str == '\n')
                {
                    break;
                }
                str++;              
            }

            card = card_user2perl(str);
            push_card_into_stack(ret, s, card);
        }        
    }

    return ret;
}

The issues were you never allocated memory at all. Using malloc to allocate memory is a must in C. You tried to use several tricks found in higher level languages. C does not manage your memory for you … ever…

solved Spaces not being replaced with newlines