How to set the first N characters of a string to '*' in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main() {
    char string[32] = "c c++ java python";
    int n = 5;

    memset(string, '*', n * sizeof(string[0])); 
  
    printf("%s\n", string);
  
    return 0;
}



/*
run:

***** java python

*/

 



answered Apr 2, 2024 by avibootz

Related questions

1 answer 121 views
2 answers 149 views
1 answer 130 views
1 answer 136 views
1 answer 174 views
1 answer 171 views
...