Print first N characters of a string using printf
#include <stdio.h>
int main(int argc, char *argv[])
{
char *p = "My Name is Neo";
printf("First 5 bytes of string is '%.5s'\n", p);
return 0;
}
Result
[neo@techpulp ex]# gcc example.c -o example [neo@techpulp ex]# ./example First 5 bytes of string is 'My Na' [neo@techpulp ex]#

