# Checking if a element is passed as input or not?

Usually most of the C programs I had learned in my school were expecting an input from start itself. Yet it's not always the case and it's a common principle to **never ever trust the user input**.

In C you can can check if the user input is valid or not by checking if it's value is 1 while reading. A sample program to do this is as shown below:

![](/files/-MkFfDxV9bfWtHTf5C7U)

According to function definition shared by Selvaraj:

scanf - On success, these functions return the number of input items successfully matched and assigned; this can be fewer than provided for, or even zero, in the event of an early matching failure. The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set to indicate the error.

A useful stackoverflow answer mentioning this

{% embed url="<https://stackoverflow.com/questions/4159985/while-scanf-eof-or-scanf-1>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.kurianbenoy.com/c-programming-language/checking-if-a-element-is-passed-as-input-or-not.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
