I want to print characters only from input string
If input contains characters, numbers and special symbols then output contain characters only. For example if input string is ” Shi&+358@57rek” Then output will be “shirek”.
Will anyone please help me?
Here,is the program to print only characters from a string.If input contains characters,numbers and special symbols in C Language:
#include <stdio.h>
int main() {
char line[150];
printf(“Enter a string: “);
fgets(line, sizeof(line), stdin); // take input
for (int i = 0, j; line[i] != ‘\0’; ++i) {
// enter the loop if the character is not an alphabet
// and not the null character
while (!(line[i] >= ‘a’ && line[i] <= ‘z’) && !(line[i] >= ‘A’ && line[i] <= ‘Z’) && !(line[i] == ‘\0’)) {
for (j = i; line[j] != ‘\0’; ++j) {
// if jth element of line is not an alphabet,
// assign the value of (j+1)th element to the jth element
line[j] = line[j + 1];
}
line[j] = ‘\0’;
}
}
printf(“Output String: “);
puts(line);
return 0;
}
In Above Program,It takes a string input from the user and stores in the variable line. And then a for loop is used to interate over the characters of the input string.If the characters in a string are not an alphabet,then it will remove from the given input string and position of the remaining characters are shifted to the left side one by one
I Hope this answer helped you.
Thank you!