First, I am completely new and learning on my own. I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.
My result as compiled by gcc -o testing testing.c
This prints.
test
t1,e2,s3,t4,
5,
As you can imagine, I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. As mentioned, I am new to programming. I believe it is because the program is not exiting the loop. I did the temperature example with "while (fahr <= upper)" and the printf printed.
Code:
#include <stdio.h>
//Use to test ideas and formats//
main()
{
int c, nc;
nc = 0;
printf ("This prints.\n");
while ((c = getchar()) != EOF)
{
++nc;
putchar(c);
printf("%d,", nc);
}
printf ("Why doesn't this print?");
printf ("I would like to print the sum of nc: %d", nc);
}
This prints.
test
t1,e2,s3,t4,
5,
As you can imagine, I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. As mentioned, I am new to programming. I believe it is because the program is not exiting the loop. I did the temperature example with "while (fahr <= upper)" and the printf printed.
Comment