top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to remove all characters in a string except alphabet?

0 votes
783 views
How to remove all characters in a string except alphabet?
posted Mar 9, 2016 by Sumana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
#include<stdio.h>
int main(){
    char line[150];
    int i,j;
    printf("Enter a string: ");
    gets(line);
    for(i=0; line[i]!='\0'; ++i)
    {
        while (!((line[i]>='a'&&line[i]<='z') || (line[i]>='A'&&line[i]<='Z' || line[i]=='\0')))
        {
            for(j=i;line[j]!='\0';++j)
            {
                line[j]=line[j+1];
            }
            line[j]='\0';
        }
    }
    printf("Output String: ");
    puts(line);
    return 0;
}

Output:

Enter a string: p2'r"o@gram84iz./
Output String: programiz
answer Mar 9, 2016 by Shivaranjini
Correct me if i am wrong, but don't you think in for loop instead of ++i/++j it should be i++/j++?
0 votes
#include<stdio.h>
#include<stdlib.h>
void main(){
    char line[150];
    clrscr();
    int i,j;
    printf("Enter a string: ");
    gets(line);
    for(i=0; line[i]!='\0'; ++i)
    {
        while (!((line[i]>='a'&&line[i]<='z') || (line[i]>='A'&&line[i]<='Z' || line[i]=='\0')))
        {
            for(j=i;line[j]!='\0';++j)
            {
                line[j]=line[j+1];
            }
            line[j]='\0';
        }
    }
    printf("Output String: ");
    puts(line);
    getch();
}
answer Mar 10, 2016 by Ashish Kumar Khanna
Similar Questions
+3 votes

Given a string and a positive integer d. Some characters may be repeated in the given string. Rearrange characters of the given string such that the same characters become d distance away from each other. Note that there can be many possible rearrangements, the output should be one of the possible rearrangements.

example:
Input:  "abb", d = 2
Output: "bab"
+1 vote

For example : input string is "xyz".
output should be
- xy z
- x yz
- x y z

+1 vote

How to create a c program to print a alphabet in the form of stars for ex.
A should be printed something like

   *
  * *
 *****
*     *

Do we have any standard algo???

...