i am a learner of ‘C’ and written a code, but after i compile it, shows a Debug Error message, here is the code:
#include<stdio.h>
void main()
{
int n,i=1;
char c;
printf("Enter Charecter:\t");
scanf("%s",&c);
printf("Repeat Time\t");
scanf("%d",&n);
n=n;
while (i <= n)
{
printf("%c",c);
i++;
}
}
Pls tell me why this happens and how to solve it
I’m not sure you understood the answer to your other question: Odd loop does not work using %c
These format specifiers are each used for a specific job.
If you want to get a:
stdinuse%c.%s.%d.This code:
Will read 1 character from
stdinand will leave a newline ('\n') character there. So let’s say the user entered the letterAin thestdinbuffer you have:The
scanf()will pull'A'and store it in yourchar cand will leave the newline character. Next it will ask for your int and the user might input5.stdinnow has:The
scanf()will take5and place it inint n. If you want to consume that ‘\n’ there are a number of options, one would be: