Monday, August 2, 2010

Character Input and Output

1. Write a program to print the value of EOF.


/*
This program is solution for 4 module problem set.

Author: Afiz'S
Date: 02/08/2010
*/
#include

main() // main function
{
char c=getchar();
printf("In the begining The value of ( c!=EOF )= %d \n",(c!=EOF));
while(c!=EOF)
c=getchar();
printf("At the ending The value of ( c!=EOF )= %d \n",(c!=EOF));

}


2.Write a program to read and accept 5 single characters from the keyboard

/*
Write a program to read and accept 5 single characters from the keyboard
Author: Afiz'S
Date: 02/08/2010
*/
#include

main() // main function
{
int i;
char c=getchar();
for(i=0;i<5;i++) // to accept 5 single characters { putchar(c); // through single character to output c=getchar(); } printf("\n"); } // end of the program.



3.Write a program to count characters of input.


/*
Write a program to count characters of input.
Author: Afiz'S
Date: 02/08/2010
*/
#include

main() // main function
{

char c = getchar();
int i=0;
while(c!=EOF)
{
i++;
//putchar(c);
//printf("\n");
c=getchar();
}

printf("Number of characters : %d\n",i);

}

No comments: