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

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main() {
    char s[] = "c programming";
    int N = 5;
    
    printf("%s", s + strlen(s) - N);
  
    return 0;
}
  
 
   
  
  
/*
run:
  
mming
  
*/

 



answered Oct 5, 2021 by avibootz

Related questions

...