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 136 views
1 answer 120 views
2 answers 148 views
1 answer 135 views
1 answer 174 views
1 answer 170 views
...