How to print the first 4 characters of a string in C

1 Answer

0 votes
#include <stdio.h>
 
int main() {
    char s[] = "c programming";
     
    printf("%.*s", 4, s);
 
    return 0;
}
 
 
 
  
 
 
/*
run:
 
c pr
 
*/

 



answered Oct 5, 2021 by avibootz

Related questions

1 answer 123 views
1 answer 219 views
1 answer 140 views
1 answer 119 views
1 answer 122 views
...