Home > front end >  Using for loop in C
Using for loop in C

Time:06-18

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

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() { enter code herechar alpha_U; enter code hereprintf("Enter the letter from where you want in upper case: "); enter code herescanf("%c", &alpha_U);

enter code herefor (char i = alpha_U; i <= 'Z'; (int)i ) { enter code hereprintf("%c", i); }

return 0; }

  • Related