Learning C (via K & R) using xcode

I am learning C with the C programming language (K & R).

Since I don’t particularly want to iterate over the text editor and run gcc, I decided to use xcode as the IDE. Until now, I could follow examples of books without problems up to section 1.5.2.

If a valid (?) Program is specified ...

#include <stdio.h>

void main()
{
    long nc;

    nc = 0;
    while (getchar() != EOF)
        ++nc;
    printf("%ld\n", nc);
}

... I do not get the final conclusion telling me how many characters were in my input. I enter my input through the xcode console window.

After some debugging, it looks like my program is stuck in a while loop and never encounters an EOF token. To do this, I replaced the new line as a new condition, replacing EOFwith "\n", which also does nothing and gives me an int to prevent pointer comparisons.

What am I doing wrong here?

K & R xcode?

+3
1

^D (control-d), EOF.

, getchar '\n', "\n". char ; char . , , , .

+11

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


All Articles