How to stop reading from stdin console in C

I am new to C programming. While I was trying to code, I ran into this problem. Sorry if the solution is obvious and I posted it here.

#include <stdio.h>
int main(){
int T = 2;
    while(T--){

        c = getc(stdin);
        while( (c != '\n') && (c != EOF)){
           // do some work
        c = getc(stdin);    
       }
    }
return 0;
}

I want that if I have several string inputs in several lines, for example,

Hithere

howareyou

Iamgood

And then, if after reading the characters “ hith ” the while loop breaks , the next character that fgetc (stdin) will read should be from the second line ( howareyou ) NOT characters from “ Hithere ”.

, 3 3 . - . , , . , , ..

. , .

+4
3

.

    while( (c != '\n')|| (c != EOF)){

:

    while( (c != '\n') && (c != EOF)){
+2

( , , !), fgets , .

+1

, . , Windows \r\n, Unix \n.

+1

Source: https://habr.com/ru/post/1539391/


All Articles