Click here to Skip to main content
15,891,856 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Thanks Pin
mla15427-Dec-06 2:06
mla15427-Dec-06 2:06 
GeneralRe: Thanks Pin
prasad_som27-Dec-06 2:30
prasad_som27-Dec-06 2:30 
AnswerRe: TextBox creation, w/o resource editor? Pin
Hamid_RT26-Dec-06 6:35
Hamid_RT26-Dec-06 6:35 
QuestionProblem with Debug compiler after installing LIB files Pin
ndfspeed197126-Dec-06 4:04
ndfspeed197126-Dec-06 4:04 
AnswerRe: Problem with Debug compiler after installing LIB files Pin
ndfspeed197126-Dec-06 4:08
ndfspeed197126-Dec-06 4:08 
GeneralRe: Problem with Debug compiler after installing LIB files Pin
Mark Salsbery26-Dec-06 5:53
Mark Salsbery26-Dec-06 5:53 
Questionhow to code a c++ only accept digit with limit? Pin
Member 367224126-Dec-06 3:18
Member 367224126-Dec-06 3:18 
AnswerRe: how to code a c++ only accept digit with limit? Pin
John R. Shaw26-Dec-06 4:43
John R. Shaw26-Dec-06 4:43 
You need to initialize the ‘n’ variable, because if the first call to ‘scanf’ fails the value will still be undefined.

How you are using ‘scanf’ will only convert digits, otherwise it failes, and you should check the return value of the function to determine if it was successful.

Your ‘while’ will not exit until a value has been enter in the required range, so there is no reason to check after the loop has exited.

If you really want to verify each digit as it is entered, then you will need to gather the digits one at a time, in to a character buffer, and call ‘isdigit’ to check each character as it is entered. After gathering digits, use ‘atoi’ to convert it to ‘int’ and then check the range. (Do not forget to make sure the character buffer ends with character ‘\0’.)

Simplified version of your code:
void main()
{
    int n = 0;

    while(n < 0 || n > 100)
   {
        printf("Enter digit (0 to 100) > ");
        scanf("%d", &n); // ignoring return value - ok here
        if(n < 0 || n > 100)
            printf("Invalid! Reenter digits >\n");
    }
}



INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

QuestionCan't use Undo in Edit View Pin
Max++26-Dec-06 3:07
Max++26-Dec-06 3:07 
AnswerRe: Can't use Undo in Edit View Pin
prasad_som26-Dec-06 4:33
prasad_som26-Dec-06 4:33 
GeneralRe: Can't use Undo in Edit View Pin
Max++26-Dec-06 4:46
Max++26-Dec-06 4:46 
GeneralRe: Can't use Undo in Edit View Pin
Max++26-Dec-06 5:44
Max++26-Dec-06 5:44 
AnswerRe: Can't use Undo in Edit View Pin
prasad_som26-Dec-06 18:12
prasad_som26-Dec-06 18:12 
GeneralRe: Can't use Undo in Edit View Pin
karle26-Dec-06 8:33
karle26-Dec-06 8:33 
QuestionHow to get files and folders name of windows\\system32 directory for Windows XP 64 bit OS by programming Pin
ashtwin26-Dec-06 2:43
ashtwin26-Dec-06 2:43 
AnswerRe: How to get files and folders name of windows\\system32 directory for Windows XP 64 bit OS by programming Pin
Michael Dunn26-Dec-06 15:55
sitebuilderMichael Dunn26-Dec-06 15:55 
AnswerRe: How to get files and folders name of windows\\system32 directory for Windows XP 64 bit OS by programming Pin
ashtwin26-Dec-06 23:26
ashtwin26-Dec-06 23:26 
QuestionUDP multicast problem Pin
eli1502197926-Dec-06 2:21
eli1502197926-Dec-06 2:21 
AnswerRe: UDP multicast problem Pin
Mark Salsbery26-Dec-06 5:58
Mark Salsbery26-Dec-06 5:58 
QuestionStopping user interaction from dialogs. How ? Pin
Sakthiu26-Dec-06 1:31
Sakthiu26-Dec-06 1:31 
QuestionRe: Stopping user interaction from dialogs. How ? Pin
prasad_som26-Dec-06 2:05
prasad_som26-Dec-06 2:05 
QuestionRe: Stopping user interaction from dialogs. How ? Pin
Sakthiu26-Dec-06 2:16
Sakthiu26-Dec-06 2:16 
QuestionRe: Stopping user interaction from dialogs. How ? Pin
prasad_som26-Dec-06 2:25
prasad_som26-Dec-06 2:25 
QuestionHow to count items in list view control and select default value in combo box Pin
amitmistry_petlad 26-Dec-06 0:54
amitmistry_petlad 26-Dec-06 0:54 
AnswerRe: How to count items in list view control and select default value in combo box Pin
prasad_som26-Dec-06 1:45
prasad_som26-Dec-06 1:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.