How to get the first 10 characters of a string in C

1 Answer

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

int main(void) {
    char s[] = "java c c++ c# php python";
    char first_10_chars[11] = "";
    
    strncpy(first_10_chars, s, 10); 
    first_10_chars[10] = '\0';

    printf("%s", first_10_chars);
}




/*
run:

java c c++

*/

 



answered Feb 23, 2021 by avibootz
edited Feb 23, 2021 by avibootz

Related questions

1 answer 154 views
1 answer 94 views
94 views asked Jul 18, 2024 by avibootz
1 answer 91 views
1 answer 137 views
1 answer 121 views
1 answer 151 views
1 answer 103 views
...