I'm new to C programming and as I was writing this program I ran into a couple of issues, the first of which was the program ignoring the second scanf function, that was fixed by adding a space before %c. The second problem that I ran into which I don't know how to fix is that whenever I enter Y into the second scanf function, the program exits and gives me an error.The other if commands work perfectly. I inserted a printf before the loop inside the if(a=='Y') just to check where the program is exiting and it didn't print it, seems like the issue is in the if command. Here's the code
Code:#include<stdio.h> int main(){ int i,b; char c[100],a; for(i=0;i<100;i++){ printf("Please enter a character\n"); scanf(" %c",&c[i]); if(c[i]=='0'){ break; } } printf("If you want to print the entered characters type Y, otherwise type N\n"); scanf(" %c",&a); if(a=='Y'){ for(i=b;b>=0;b--){ printf("%c and it's location in the array is %d\n",c[b],b); } } else if(a=='N'){ printf("Goodbye!"); } else{ printf("Error"); } return 0; }