Question: So I'm writing a small program (I'm new to C, coming from C++), and I want to take in a string of maximum length ten.

I declare a character array as

```
#define SYMBOL_MAX_LEN 10 //Maximum length a symbol can be from the user (NOT including null character)
.
.
.
char symbol[SYMBOL_MAX_LEN + 1]; //Holds the symbol given by the user (+1 for null character)

```

So why is it when I use:

```
scanf("%s", symbol); //Take in a symbol given by the user as a string

```

I am able to type '01234567890', and the program will still store the entire value?

My questions are:

1. Does scanf not prevent values from being recorded in the adjacent
blocks of memory after `symbol`?
2. How could I prevent the user from entering a value of greater than length `SYMBOL_MAX_LEN`?
3. Does scanf put the null terminating character into `symbol` automatically, or is that something I will need to do manually?

Answer: 
> 
> Does `scanf` not prevent values from being recorded in the adjacent blocks of memory after symbol?
> 
> 
> 

As far as I know, No.

> 
> How could I prevent the user from entering a value of greater than length SYMBOL\_MAX\_LEN?
> 
> 
> 

By using buffer safe functions like `fgets`.

> 
> Does `scanf` put the null terminating character into symbol automatically, or is that something I will need to do manually?
> 
> 
> 

Only if the size was enough for it to put the `nul` terminator. For example if your array was of length 10 and you input 10 chars how will it put the `nul` terminator.
> 
> I am able to type '01234567890', and the program will still store the entire value? 
> 
> 
> 

This is because you are Unlucky that you are getting your desired result. This will invoke undefined behavior. 

> 
> Does `scanf` not prevent values from being recorded in the adjacent blocks of memory after symbol? 
> 
> 
> 

No. 

> 
> How could I prevent the user from entering a value of greater than length SYMBOL\_MAX\_LEN? 
> 
> 
> 

Use `fgets`. 

> 
> Does scanf put the null terminating character into symbol automatically, or is that something I will need to do manually? 
> 
> 
> 

Yes