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

1 Answer

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

int main() {
    char s[] = "c programming";
     
    printf("%s", s + strlen(s) - 4);
 
    return 0;
}
 

  
 
 
/*
run:
 
ming
 
*/

 



answered Oct 5, 2021 by avibootz

Related questions

1 answer 140 views
1 answer 139 views
1 answer 101 views
1 answer 219 views
1 answer 255 views
1 answer 147 views
...