How to get the last 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 last_10_chars[11] = "";
     
    strncpy(last_10_chars, s + strlen(s) - 10, 10); 
    last_10_chars[10] = '\0';
 
    printf("%s", last_10_chars);
}
 
 
 
 
/*
run:
 
php python
 
*/

 



answered Feb 23, 2021 by avibootz

Related questions

1 answer 159 views
1 answer 151 views
1 answer 141 views
1 answer 135 views
2 answers 278 views
1 answer 127 views
...