S
S
start_of_way2021-10-14 09:59:38
C++ / C#
start_of_way, 2021-10-14 09:59:38

How does the program receive input?

/*  Напишите программу печати всех вводимых строк, содержащих более 80 символов. */

#include <stdio.h>
int MAXLINE = 1000;

int getlinel(char line[], int MAXLINE);

int main()
{
    int len,  min = 10;
    char line[MAXLINE];
    while ((len = getlinel(line, MAXLINE)) > 0)
        if (len > 80){
            printf("%s\n", line);
        }
    return 0;
}

int getlinel(char s[], int lim)
{
    int c, i;
    for (i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; ++i)
        s[i] = c;
    if (c == '\n') {
        s[i] = c;
        ++i;
    }
    s[i] = '\0';
    return i;
 }

Here is the program (it works). How does she get input? There is no putchar() or scanf() or the like here. But WHERE does the program get input from? Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2021-10-14
@start_of_way

There is no putchar() or scanf() or the like here.

exist c = getchar().
WHERE does the program get input from?

from standard input, from which getchar reads characters.

R
Ronald McDonald, 2021-10-14
@Zoominger

for (i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; ++i)

Here. The loop reads the current character until EOL is received or Enter is pressed. Well, or the length of the string will not exceed the specified value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question