C-Program to count the number of occurrences of the letter ‘a’ in an input stream of characters terminated with a carriage return.

Program to count the number of occurrences of the letter ‘a’ in an input stream of characters terminated with a carriage return.

#include <stdio.h>

void main()

{

int count = 0, total = 0 ;

char ch ;

while (  ( ch = getchar() ) != 13 )    // 13 is ASCII value for //carriage return

{

if ( ch == ‘a’ )

{

count ++ ;

printf( “\n Retrieved letter ‘a’ number %d\n”, count ) ;

}

total ++ ;

_flushall() ;

}

printf( “\n\n %d letters a typed in a total of %d letters.”,

count, total ) ;

}

 

error: Content is protected !!