atoi

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • askcq
    New Member
    • Mar 2007
    • 63

    atoi

    main() {

    int i;
    char* ptr ="str";
    printf("%d",ato i(ptr));

    }

    no output is produced ...
    pls tell me the problem ...
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    where are you running this program from?

    Comment

    • askcq
      New Member
      • Mar 2007
      • 63

      #3
      no error it shows while compilation , but after run there is no output ...

      iam running this program using VI editor in linux

      Comment

      • Silent1Mezzo
        New Member
        • Feb 2007
        • 208

        #4
        Originally posted by askcq
        no error it shows while compilation , but after run there is no output ...

        iam running this program using VI editor in linux
        When I run this it prints out 0 for me.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Are you really trying to convert the letters s t and r to an int? atoi() returns 0 if the characters in the string do not represent an int value.

          A better choice is a string with "123".

          Comment

          • svlsr2000
            Recognized Expert New Member
            • Feb 2007
            • 181

            #6
            atoi converts till it encounters ant non numerical characters, ie till someting other then 0 to 9, is encountered. here a is not integer so atoi stops conveerting hence returns zero

            Comment

            Working...