readchar - 2 ways

#include <stdio.h>  
 int main(int argc, char *argv[])  
 {  
   int c, d;  
   long nc;  
   for (nc = 0; (d = (c = getchar()) != EOF); nc++)  
   {  
     printf("\ngetchar() value is %d \n", d);  
     printf("input is : ");  
     putchar(c);  
     printf("\neof value is %d \n", EOF);  
   }  
   printf("no of characters is %ld\n", nc);  
   return 0;  
 }  
#include <stdio.h>  
int main(int argc, char *argv[])
{

    int c, d;
    long nc = 0;
    while (d = (c = getchar()) != EOF)
    {
        printf("\ngetchar() value is %d \n", d);
        printf("input is : ");
        putchar(c);
        printf("\neof value is %d \n", EOF);
        nc++;
    }

    printf("no of characters is %ld\n", nc);
    return 0;
}  

Comments

Popular posts from this blog

Farenheit Celsius Calculator