DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   strange problem (http://www.daniweb.com/forums/thread20038.html)

navyblue Mar 12th, 2005 2:47 am
strange problem
 
#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 ???????????????????

prog-bman Mar 12th, 2005 3:48 am
Re: strange problem
 
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;
}


All times are GMT -4. The time now is 1:55 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC