-1
#include <stdio.h>

void main()
{
    char ch;

    clrscr();
    ch = 'A';
    while(ch <= 'z')
    {
       printf("%c", ch);
       ch++;
    }
    getch();
 }  

How do I remove garbage like [, ], ', \, etc. from the output of this program?

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
HuHu
  • 59
  • 1
  • 10

1 Answers1

3

Like mentioned in a comment skip everything between Z for example this way:

#include "stdio.h"
int main(){
    char ch = 'A';
    while(ch <= 'z'){
        if(ch <= 'Z' || ch >= 'a'){
            printf("%c", ch);
        } 
        ch++;
    } 
    printf("\n");
    return 0;
}

or alternatively use a for loop since you know the beginning and end of the range of values:

#include "stdio.h"
int main(){
    char ch;
    for(ch = 'A'; ch <= 'z'; ch++){
        // loop through range of ASCII values from 'A' to 'z', upper case
        // and lower case letters, and print out only alphabetic characters.
        if(ch <= 'Z' || ch >= 'a'){
            // character is in range of 'A' thru 'Z' or 'a' thru 'z'.
            printf("%c", ch);
        } 
    } 
    printf("\n");
    return 0;
}

or alternatively use the isalpha() function to detect if a character is alphabetic or not.

#include "stdio.h"

int main() {
    char ch;
    // loop through range of ASCII values from 'A' to 'z', upper case
    // and lower case letters, and print out only alphabetic characters.
    for (ch = 'A'; ch <= 'z'; ch++)  isalpha (ch) && printf ("%c", ch);
    printf("\n");
    return 0;
}
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76