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

1 Answer

0 votes
#include <stdio.h>

int main() {
    char s[] = "c programming";
    int N = 5;
    
    printf("%.*s", N, s);

    return 0;
}



 


/*
run:

c pro

*/

 



answered Mar 3, 2021 by avibootz

Related questions

1 answer 127 views
1 answer 108 views
2 answers 134 views
1 answer 126 views
1 answer 166 views
1 answer 164 views
...