# C PROGRAMS
String in C
➤ Read Display String in C
➤ 2D Array of Strings in C
➤ Find Length of String
➤ Copy Two Strings in C
➤ Concatenate Two Strings
➤ Compare two strings
➤ Reverse a String in C
➤ Palindrome string in C
➤ Uppercase to Lowercase
➤ Lowercase to Uppercase
➤ Remove all characters in String except alphabet
➤ Find Frequency of Characters
➤ Count Number of Words
➤ Count lines, words, & characters
➤ Count Vowel, Consonant, Digit, Space, Special Character
➤ String Pattern in C
➤ Copy Input to Output
Program description:- Write a C program for copy input to output.
For copy input to output using C programming, the getchar()
function can be used. The getchar()
function returns a distinctive value when there is no more input, a value that cannot be confused with any real character. This value is called EOF, for “End of File
”.
#include<stdio.h>
int main()
{
int c;
while((c=getchar())!=EOF)
putchar(c);
return 0;
}
Output:-
Hi, Copy it.
Hi, Copy it.
The statement, while((c=getchar())!=EOF)
also can be written in two lines as, c=getchar();
while (c!=EOF)
We must declare the variable c
to be a type big enough to hold any value that the getchar
function returns. We can’t use char since c must be big enough to hold EOF in addition to any possible char. Therefore we use int data type.
EOF is an integer defined in <stdio.h>, but it is not the same as any char value.
In this program copy input to output using C, The parentheses around the assignment within the condition are necessary. The precedence of != is higher than that of =, Which means that in the absence of parentheses the relational test != would be done before the assignment. So, the statement
c =
getchar
() != EOF
is equivalent to c = (
getchar
() != EOF )
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Similar C programs on String
- Remove all characters in a string except alphabet
- Find the frequency of characters in a string
- C program to count the number of words in a string
- C program to count lines words and characters in a given text
- Vowel consonant digit space special character Count in C Programming
- String pattern in C language
Programs with and without using String manipulation library functions
- Find the length of String
- Copy two Strings
- Concatenate Two Strings
- Compare two strings
- Reverse a String
- Find string is a palindrome or not
- Uppercase character into the lowercase character
- Lowercase character into the uppercase character
Multi-dimensional String