Learn ABC in C language?

Asked

Viewed 183 times

2

As I do in this code, when he type a letter read by the keyboard with the type scanf (char) it repeats until the Z?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char c;

    /*for (c= 'A'; c<='Z'; c++){
        printf("Letra =  %c\n", c);
    } */
    system("pause");
    return 0;
}

1 answer

2


Perform the scanf of the letter, and delete the counter for.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char c;
    char limit;
    scanf("%c", &c);

    if(c >= 65 && c <= 90){
         limit = 'Z';
    }else{
         limit = 'z';
    }

    for (; c<=limit; c++){
        printf("Letra =  %c\n", c);
    }
    system("pause");
    return 0;
}
  • Only works with capital letters. I put it like this and stuck it for(; c<='Z' || 'z'; c++) {

  • How do ||(or) then no for z and Z?

  • 2

    @user24857 I think you wanted to do for(; c<='Z' || c<='z'; c++) {. Your for "brake" (entered an infinite loop) because the second condition of "or" - 'z' - is always true (because it is different from zero). Already c <= 'z' may or may not be true. Only if you do the code like this, it will print other characters that are not letters (because between the intervals a-z and A-Z there are several symbols).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.