help with is digit

This is a discussion on help with is digit within the C Programming forums, part of the General Programming Boards category; hello, i'm not really sure if the problem lies in isdigit, what I do know is that it isn't doing ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    3

    help with is digit

    hello,
    i'm not really sure if the problem lies in isdigit, what I do know is that it isn't doing it's job.

    Code:
    char ErrorControl(char op,char line1[],char line2[],char line3[],char line4[],char line5[]){
        bool sure=true;
        int op_int,times=0;
           while(sure){
              op_int=op -'0';
              printf("%d",op_int);
              if((isdigit(op)) || (op_int>10)){
                               printf("test");
                               sure=false;
                               }
              else {
                    printf("\nInvalid Option!\nInput option: ");
                    scanf("%c",&op);
                    fflush(stdin);
                    times++;
                    if(times==3) {
                                 system("cls");
                                 times=0;
                                 }
                    printf("%s %s %s %s %s",line1,line2,line3,line4,line5);
                   }
              }
              return op;
    }
    this is basicly a small function I made to see if the user input is what I expected. in that if, i change the bool to false, which should cause it to exit the while.
    I ran out of ideas of what could cause this...

    Thanks
    Last edited by sightl3ss; 06-04-2009 at 08:37 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,973
    How does it not work?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    How did you #define "true" and "false"?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    3
    Quote Originally Posted by MK27 View Post
    How did you #define "true" and "false"?
    uhm what do you mean? they're keywords.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,973
    Quote Originally Posted by sightl3ss
    uhm what do you mean? they're keywords.
    They are not keywords. I assumed that you included <stdbool.h>. Did you?

    By the way, fflush(stdin) results in undefined behaviour, and you could be a little more consistent with your indentation, but good to see that you posted code in code tags
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by sightl3ss View Post
    uhm what do you mean? they're keywords.
    Sorry, I was unaware of <stdbool.h>.

    Can you describe the problem in better detail? Are you saying that "test" prints out and then the loop happens again anyway? Or "test" does not print?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    3
    Quote Originally Posted by laserlight View Post
    They are not keywords. I assumed that you included <stdbool.h>. Did you?

    By the way, fflush(stdin) results in undefined behaviour, and you could be a little more consistent with your indentation, but good to see that you posted code in code tags
    i haven't included stdbool.h, they're keywords, i'm not sure it's because of the compiler i'm using? i'm using dev c bloodshed

    and i know i wasn't very clear, i'm sorry. i'm going to review this over(having an headache right now..) and then i'll post the problems i encounter.(i kind of forgot..)
    thank you for your answers

    edit: i didn't include the whole code because it's a lot of lines(probably a lot less than what you're used to see here, still)
    anyways im using these libs:
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include<windows.h>
    #include<ctype.h>
    Last edited by sightl3ss; 06-04-2009 at 09:21 AM.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,973
    Quote Originally Posted by sightl3ss
    i haven't included stdbool.h, they're keywords, i'm not sure it's because of the compiler i'm using? i'm using dev c bloodshed
    The Bloodshed Dev-C++ IDE comes with the MinGW port of gcc, which does not have such an extension that true and false are recognised as keywords. More likely you are compiling as C++ instead of C.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by sightl3ss View Post
    edit: i didn't include the whole code because it's a lot of lines(probably a lot less than what you're used to see here, still)
    The best option is for you to describe the problem as well as you can. If that doesn't work, you could post the whole thing and someone *might* test it, but on the other hand, they might not. So try to describe the problem.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    Code:
    if((isdigit(op)) || (op_int>10)){
    will be true if op is from '0' to '9', or pretty much any character above ':' which includes
    Code:
    ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error msg instead of the result so far
    By maybabier in forum C Programming
    Replies: 25
    Last Post: 03-20-2009, 02:45 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Adding a Large number digit by digit
    By mejv3 in forum C Programming
    Replies: 1
    Last Post: 09-14-2007, 03:28 AM
  4. newbie programmer - needs help bad.
    By hortonheat in forum C Programming
    Replies: 17
    Last Post: 10-20-2004, 05:31 PM
  5. Roman number converter
    By BalanusBob in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2002, 06:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21