# Average Character

## Question

{% embed url="<https://open.kattis.com/problems/averagecharacter>" %}

## Solution

### Idea

The basic idea is easy, just to get the average ASCII value of each character in the input string.

However, if C is the language being used, things get a bit tricky regarding the input. Here, we can only use `fgets()` to read the input because white space characters cannot be ignored in this question. So, the correct way to read the input is below:

```c
#define MAX_LEN 102

if (fgets(string, MAX_LEN, stdin))
{
  string[strcspn(string, "\n")] = 0;
}
```

{% hint style="info" %}
Here the `MAX_LEN` is 2 characters more than 100 (the actual length of the string). This is because:

1. Add 1 to take the null character into account (the property of string in C)
2. Add 1 to take the `\n` character which is read by `fgets()` (the property of `fgets()` in C)
   {% endhint %}

### Code

{% @github-files/github-code-block url="<https://github.com/mendax1234/Coding-Problems/blob/main/kattis/averagecharacter/averagecharacter.c>" %}


---

# 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://wenbo-notes.gitbook.io/coding/kattis/easy/average-character.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.
