element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) Bug in ULP strtol?
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 177 subscribers
  • Views 343 views
  • Users 0 members are here
Related

Bug in ULP strtol?

autodeskguest
autodeskguest over 16 years ago

ULP -      output("c:
eagle_debug.txt", "wt") {

          printf("Starting a run of ULP %s - ", argv[0]);

          int t = time();

          printf("It is now %02d:%02d:%02d\n",

          t2hour(t), t2minute(t), t2second(t));

}

 

     int n = 16;

     for (int i = 0; i <= n; i++) {

 

     string outputs;

     int outputu;

 

     sprintf(outputs,"%2.2u",i);

 

                output("c:
eagle_debug.txt", "at") {

                           printf("i as string = %s - ", outputs);

                           outputu = strtol(outputs);

                           printf("i as strtol = %u\n", outputu);

                           printf("\n");

                    }          

 

 

     }

 

 

 

Output

 

Starting a run of ULP C:/Program

Files/EAGLE-UserFiles/ulp/test_strtol.ulp - It is now 09:26:16

i as string = 00 - i as strtol = 0

 

i as string = 01 - i as strtol = 1

 

i as string = 02 - i as strtol = 2

 

i as string = 03 - i as strtol = 3

 

i as string = 04 - i as strtol = 4

 

i as string = 05 - i as strtol = 5

 

i as string = 06 - i as strtol = 6

 

i as string = 07 - i as strtol = 7

 

i as string = 08 - i as strtol = 0

 

i as string = 09 - i as strtol = 0

 

i as string = 10 - i as strtol = 10

 

i as string = 11 - i as strtol = 11

 

i as string = 12 - i as strtol = 12

 

i as string = 13 - i as strtol = 13

 

i as string = 14 - i as strtol = 14

 

i as string = 15 - i as strtol = 15

 

i as string = 16 - i as strtol = 16

 

 

Glenn

 

  • Sign in to reply
  • Cancel
Parents
  • autodeskguest
    autodeskguest over 16 years ago

    Hello,

     

    Glenn Jones wrote:

    i as string = 07 - i as strtol = 7

     

    i as string = 08 - i as strtol = 0

     

    i as string = 09 - i as strtol = 0

     

    i as string = 10 - i as strtol = 10

     

    This is not a bug. Numbers with leading zeros are interpreted as octal

    numbers and 08 and 09 are not valid octal numbers. Since strtol is not

    able to convert the string to a number it returns 0.

    Search the help for 'strtol()' and 'integer constants' for details.

     

    To avoid leading zeros in the output and have the numbers padded with

    spaces you could use

       sprintf(outputs,"% 2u",i);

    instead. The added space acts as padding character. I stripped the .2

    from the format specifier because the precision specifier only makes

    sense for real numbers.

     

     

    Regards,

    Christoph

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • autodeskguest
    autodeskguest over 16 years ago in reply to autodeskguest

    Christoph Wurzinger wrote:

    Hello,

     

    Glenn Jones wrote:

    i as string = 07 - i as strtol = 7

     

    i as string = 08 - i as strtol = 0

     

    i as string = 09 - i as strtol = 0

     

    i as string = 10 - i as strtol = 10

     

    This is not a bug. Numbers with leading zeros are interpreted as octal

    numbers and 08 and 09 are not valid octal numbers. Since strtol is not

    able to convert the string to a number it returns 0.

    Search the help for 'strtol()' and 'integer constants' for details.

     

    To avoid leading zeros in the output and have the numbers padded with

    spaces you could use

      sprintf(outputs,"% 2u",i);

    instead. The added space acts as padding character. I stripped the .2

    from the format specifier because the precision specifier only makes

    sense for real numbers.

     

     

    Regards,

    Christoph

     

    Hi Christoph,

     

    I was parsing input that has leading zero's and converting to integer so

    I could increase the value by one and make a string out of it again.

     

    So I will strip off leading zeros, increment and then print back to a

    zero leading string. The leading zero is not really required but i would

    rather not modify the data as supplied more then necessary.

     

    And you are correct what I wanted was sprintf(outputs,"%02u",i);

     

    Thanks for the explanation.

     

    Glenn

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • autodeskguest
    autodeskguest over 16 years ago in reply to autodeskguest

    Christoph Wurzinger wrote:

    Hello,

     

    Glenn Jones wrote:

    i as string = 07 - i as strtol = 7

     

    i as string = 08 - i as strtol = 0

     

    i as string = 09 - i as strtol = 0

     

    i as string = 10 - i as strtol = 10

     

    This is not a bug. Numbers with leading zeros are interpreted as octal

    numbers and 08 and 09 are not valid octal numbers. Since strtol is not

    able to convert the string to a number it returns 0.

    Search the help for 'strtol()' and 'integer constants' for details.

     

    To avoid leading zeros in the output and have the numbers padded with

    spaces you could use

      sprintf(outputs,"% 2u",i);

    instead. The added space acts as padding character. I stripped the .2

    from the format specifier because the precision specifier only makes

    sense for real numbers.

     

     

    Regards,

    Christoph

     

    Hi Christoph,

     

    I was parsing input that has leading zero's and converting to integer so

    I could increase the value by one and make a string out of it again.

     

    So I will strip off leading zeros, increment and then print back to a

    zero leading string. The leading zero is not really required but i would

    rather not modify the data as supplied more then necessary.

     

    And you are correct what I wanted was sprintf(outputs,"%02u",i);

     

    Thanks for the explanation.

     

    Glenn

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube