1

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;
}
user438383
  • 5,716
  • 8
  • 28
  • 43
dev op
  • 13
  • 4
  • 4
    You have to write scanf(" %c", &alpha_U); That is you need to pass the address of the variable alpha_U. Also it is desirable to place a leading space in the format string to skip white spaces. – Vlad from Moscow Jun 18 '22 at 09:21
  • Thanks a lot, I am still learning, I am sorry for asking this , silly mistake from my side, I didn't stored the entered value. Thank You! – dev op Jun 18 '22 at 09:27
  • Please see [this](https://stackoverflow.com/questions/57842756/why-should-i-always-enable-compiler-warnings) – n. m. could be an AI Jun 18 '22 at 09:31

3 Answers3

2

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);

C3n21
  • 46
  • 2
1
#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;

}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Bo-ne
  • 19
  • 2
1

I am also starting out with C so I apologize 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;
}
c_starter
  • 40
  • 8