How to use sprintf with spaces in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
  
int main()
{
    unsigned char str[32] = "C Programming", result[128] = "";
    int j = 0, size = strlen(str);
 
    for (int i = 0; i < size; i++, j += 2) { 
        sprintf((char*)result + j, "%c%c", str[i], ' ');
    }
     
    result[j] = '\0'; 
      
    printf("%s\n", result);
 
    return 0;
}
 
 
 
 
/*
run:
 
C   P r o g r a m m i n g
 
*/

 



answered Nov 18, 2024 by avibootz

Related questions

1 answer 219 views
1 answer 191 views
2 answers 233 views
233 views asked May 27, 2020 by avibootz
2 answers 208 views
208 views asked Jul 26, 2017 by avibootz
3 answers 264 views
2 answers 143 views
143 views asked Dec 5, 2024 by avibootz
...