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/).
for example substring extraction function (extracts substring to the buff)

```
char *strpart(char *str, char *buff, int start, int end)
{
    int len = str != NULL ? strlen(str) : -1 ;
    char *ptr = buff;

    if (start > end || end > len - 1 || len == -1 || buff == NULL) return NULL;

    for (int index = start; index <= end; index++)
    {
        *ptr++ = *(str + index);
    }
    *ptr = '\0';
    return buff;
}

```