C store digit and spaces in char array [closed]

Here this should work for you

#include <stdio.h>

int main(void) 
{
    char m[100];
    int i;
    for(i = 0; i < 5; i++)
    {
       if(i == 2)
           m[i] = ' ';
       else
           m[i] = '0' + i; //<< Note ascii of 0 is 48
    }
    m[i]= '\0';
    printf("%s",m);
    return 0;
}

Leave a Comment