Question: Each input line to the above programs, either from keyboard or from the text file, ends with an invisible new line character. Modify the program

Each input line to the above programs, either from keyboard or from the text file, ends with an invisible new line character. Modify the program countChar so that it counts only visible characters, i.e., new line character is not counted. Name your program countChar3.c.

greetings.txt:

hello

how are you

I am good

countChar.c

#include //define EOF

main() {

int c;

int count = 0;

c = getchar();

while(c != EOF) /* no end of file */

{

count++; //include spaces and ' '

c = getchars(); /* read next */

}

printf("# of chars: %d " ,count);

}

Sample Inputs/Outputs:

red 318 % gcc countChar3.c -o cc3

red 319 % cc3

hello

how are you?

I am good and Thanks!

^D

# of chars: 38

red 320 % cc3

hello

how are you

I am good

^D

# of chars: 25

red 320 % cc3 < greetings.txt

# of chars: 25

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!