Question: I have an array:

```
char arr[]="This is the string";

```

For instance, if I want to print only first 5 characters of that string, I have tried the following:

```
printf("%-5s",arr);

```

But it is printing whole string. Why?

Answer: 
`-` is a printf formater for *justification*, not *precision*.

What you want is the `.` formater which is used for precision :

```
printf("%.5s", arr);

```

This will print the first 5 elements of `arr`.

If you want to learn more about printf formaters, take a look at [this link](http://www.cplusplus.com/reference/cstdio/printf/).
You can do it quite simply in a number of ways. With a loop, looping the number of times desired, picking off chars each time, you can walk a pointer down the string an temporary nul-terminate after the 5th character, or you can simply use `strncpy` to copy 5 chars to a buffer and print that. (that is probably the simplest), e.g.

```
#include <stdio.h>
#include <string.h>

int main (void)
{
    char arr[]="This is the string",
        buf[sizeof arr] = "";      /* note: nul-termination via initialization */

    strncpy (buf, arr, 5);

    printf ("'%s'\n", buf);

    return 0;
}

```

**Example Use/Output**

```
$ ./bin/strncpy
'This '

```

Look things over and let me know if you have any questions.