Home > Blockchain >  take user's input and then print the alphabet series
take user's input and then print the alphabet series

Time:06-19

My aim is to take user's input and then print the alphabet series. Printing the alphabet series from the point the user entered the input.

#include<stdio.h>

int main(){
    char alpha_U;
    printf("Enter the letter from where you want in upper case: ");
    scanf("%c",alpha_U);
    
    for(char i = alpha_U; i <= 'Z'; i  ){
        printf("%c",i);
    }
    
    return 0;
}

CodePudding user response:

Your code is almost fine, except for

scanf("%c", alpha_U);

which requires a pointer as second argument.

I am not expert of C or C programming, so the thing I would suggest you is to checkout the documentation on cplusplus.com.

Specifically, here is how scanf is documented:

https://cplusplus.com/reference/cstdio/scanf/

The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.

so in your case you should be doing

scanf("%c", &alpha_U);

CodePudding user response:

#include<stdio.h>

int main()
{
    char alpha_U;
    printf("Enter the letter from where you want in upper case: ");
    scanf("%c", &alpha_U);//Here,you should add '&' before 'alpha_U'

    for (char i = alpha_U; i <= 'Z'; (int)i  ) {//Then,add '(int)' before 'i'
        printf("%c", i);
    }

    return 0;

}

CodePudding user response:

I am also a starting out with C so I appolize if I missed any details.

scanf("%c", alpha_U);

is missing & in the front of the variable. Corrected below.

scanf("%c",&alpha_U);

I rewrote the code so I can get the user input in the main function.

#include<stdio.h>
#include <ctype.h>

int main(int argc, char *argv[]){
    char lowerCase,upperCase;
        printf("Enter one chacters to be capitalized\n");
        scanf("%c", &lowerCase);
        upperCase = toupper(lowerCase);
        printf("%c",upperCase);

    return 0;
}
  • Related