Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using for loop in C

I have started C tutorial.
The issue is with my code.
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.
Here is the code.

#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;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading