0

#include<stdio.h>
main()
{int i;
do{
printf("*");
scanf("%d",&i);
}while(1);
}
this is a sample program,but u don't look down upon it
when u input a unnummber ,there will no stop!
i want to know why ???????????????????

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by prog-bman
0

Well it's not a strange problem considering it's doing what it is supposed to do.

First off, when posting code please use code tags. Read here

Second, main returns an int it should be int main(void).

Third, When writing please use complete sentences and use "you" not "u". Also using a bunch of question marks doesn't make your question more of a question.

Fourth, what your program is doing is looping while (1). This is saying while true repeat(any non zero number is "true"). What you were probably going for was something like this:

#include <stdio.h>

int main(void)
{
    int number;
    do
    {
        /*notice the spacing it makes your code much easier to read*/
        printf("*\n");
        printf("Enter 0 if you want to quit\n");
        scanf("%d",&number);
    
    }while (number != 0);
    
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.