Announcement

Collapse
No announcement yet.

C programming i/o validation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C programming i/o validation

    Anyone know of a comprehensive site, that talks about the:
    while (scanf("%d", &var) == 1)
    {
    while (getchar() != 'n');
    printf("Try again: ");
    }

    As i'm trying to figure out why, it's compared to 1 (i get it one variable is being pointed to and written too. So 1, and if there was &var, var) it'd be == 2), naturally the var without the &ampersand means the var is a char, or a string variable, and does not need one.)

    However scanf("%d", &var); has serious issues with taking a string it will crash the program they called it some End of line error or something. As it's set to read integers, and so if a string is intered it will go nuts.

    Anyways i'm looking for a comprehensive site that will explain in detail the comparison of scanf(""); and some detail as to better data validation as although the above method will work and block a string from being entered till a number is entered, if you enter a # then a string after it. "# char" the program will also crash again, and thus the above fix is void, however if it's just a number (as it's suppose to be, then it works fine and goes through the rest of the program code to compare the number with the conditionals set for it, and it's limits.)

    Anyways if anyone happens to know, of any good sites that aren't too full of ego and bullshit.

    Let me know.

    if not, no worries. I just get angry when something makes nosense to me yet i can still use it (to make things work) but not knowing why it's working the way it does, is very annoying.

    Everything in the program works fine, and no it's not a program / project for school it's just practice.

    Reading what degree to determine the angle limiting the degrees so they can't go below 0 or over 360 degrees.

    That sort've thing. It's done and built but i'm trying to figure out better data validation. As i feel, it'd be great to be capable to build programs 100% error free at least syntax wise, not that they won't be incompatible with other systems and stuffs.

    Most should work on any system provided you follow the C99 standards.

    Anyways let me know.

    Thanks.

  • #2
    http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?fscan.hlp
    Quakeone.com - Being exactly one-half good and one-half evil has advantages. When a portal opens to the antimatter universe, my opposite is just me with a goatee.

    So while you guys all have to fight your anti-matter counterparts, me and my evil twin will be drinking a beer laughing at you guys ...

    Comment


    • #3
      That has to be out of date as %d being a decimal integer? and %o? never even heard of it.

      Said it was 2003, that page you gave me and i have a book from 2003 or 2004 and it's not the C99 standard.

      And since the C99 standard is the ISO now.

      For C at least. None of that is accurate least not the signifiers that they listed on that page.

      However it could've been a C++ page, as i donno much about C++ anymore last time i dabbled in it, it was 6.0 and apparently it's standard is different now as well, so thus all i knew is 60% likely to have changed.

      Thanks for the url though.

      Comment


      • #4
        uh, %d has always been a decimal integer. and %o has been around forever. C99 added stuff like %a %zu %ju and some other stuff. Try looking at the man page for scanf
        "If we fight for money I'll stop hitting you when you ask me to. If we fight for honor, I'll stop hitting you when I feel like it." - Rickson Gracie

        Comment


        • #5
          Originally posted by mithril View Post
          uh, %d has always been a decimal integer. and %o has been around forever. C99 added stuff like %a %zu %ju and some other stuff. Try looking at the man page for scanf
          I know %d as being an integer (whole number) it contains no decimals %f floats are what are your decimals (real numbers).

          %o is not in my 2005 C book.

          I don't think %o exists anymore.

          I ain't never heard of it anyways, less it's for the fscanf() not the scanf() as scanf() only has 5 signifiers for it.

          Which are, %c single character %d integer %f float %s string %u unsigned integer (positive only no negatives, value is doubled -1 of ints whole value).

          But anyways far as i know stuff from 2003 and back are not C99 standard.

          As i owned a book of C from 2003 or 2004 before and nothing in it was working and i was told it's because the standard changed.

          Personally the only real noticable change i noticed though was the int main (void) {

          the (void) command to the main function of the language.

          Other than that, i am not sure as i didn't know C fully before, and i still don't.

          So like i said, less it was a breakdown of signifiers for (all these scanf's) like all the other ones other then scanf() it self....

          shrugs.

          Comment


          • #6
            http://www.tin.org/bin/man.cgi?section=3&topic=scanf

            that page conforms to C99, but you should really read the docs for the C library you are using. The glibc library has an excellent reference manual on their website. Hopefully your C library does as well
            "If we fight for money I'll stop hitting you when you ask me to. If we fight for honor, I'll stop hitting you when I feel like it." - Rickson Gracie

            Comment


            • #7
              Thanks Mithy.

              I never did go through dev-c++'s text's yet. Was using gcc through msdos prompt for long time only recently started to use the gui of Dev-c++ rather then typing gcc -o filename.c filename

              As i know they were going to have us using the ide of dev-c++ in class, so i figured i better start using it again, rather then practicing with notepad and msdos.

              Never even tried to make a makefile yet, even though i know i have the make program as the system environment vars are modified to have Dev-C++'s directory in the system environment and i guess make.exe is in the bin directory of the dev-c++ program.

              I'll have to try it sometime.

              Not that it matters if i'm going to use the ide... but least i'll know how sometime, never read through the txt file i saved of make --help yet either.

              Lazy, lazy.... I probably drink too much and play guitar too much.

              Anyways thanks for that link. ^^

              Guess baker's link wasn't wrong than, %o does exist, and %d is a decimal integer (weirdly, i thought it only accepted whole numbers less they call it a decimal integer because c will often change the type if it determines it's a float rather then an integer... or something.)

              Anyways thanks.

              I'll look it over after, i got class today.

              Comment


              • #8
                A decimal integer is an integer in base 10. An octal integer is base 8 and a hexadecimal integer is base 16...they are all integers not floats. %f %e %g ... are floats. %d is integer in base 10.
                "If we fight for money I'll stop hitting you when you ask me to. If we fight for honor, I'll stop hitting you when I feel like it." - Rickson Gracie

                Comment

                Working...
                X