Add space to a string

后端 未结 2 1433
误落风尘
误落风尘 2021-01-21 04:41

I am trying to add a space to each space until column = 0. I am not sure how to do this.

The problem is the following. If you look at a newspaper you will s

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-21 05:01

    This is what i made. It's far from ideal, but you get the point. You just need to put in conditions, like when the string entered is larger or equal than 40 chars, to skip the procedure.

    #include
    #include
    #include
    
    int main(void)
    {
    int i = 0;  // first just initialiaze stuff
    char ch[40]; // memset the arrays, get the string
    memset(ch, '\0', 40);
    gets(ch);
    
    int diff = 40 - strlen(ch);
    int spaces = 0;
    while(i

提交回复
热议问题