Thread: gcc/borland and sscanf format specifiers

  1. #1
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166

    Angry gcc/borland and sscanf format specifiers

    Hello,

    I guess it was a mistake to trust cygwin gcc 3.2 alone for the last weeks. I've just compiled my application with the Borland Command Line Tools 5.5.x. But this time the command line interface - provided by http://argtable.sourceforge.net/ - wouldn't work correctly.
    I checked the argtable library function for parsing the command line and found this:
    Code:
    /*-- scan an int value --*/
    // eliminated space between %i and %n to make it work with borland
          if (sscanf(str,"%i %n",&intval,&length) !=1) 
             return -1;
    This first error (str,"%i %n"...) was obvious. I just wonder why GCC 3.2 didn't warn me? Does GCC ignore such spaces in fomat strings or correct such errors quietly or - to make it even worse - not notice them at all? After removing the space the Borland compiled program would work as expected.

    But then I found this some lines below:
    Code:
    /*-- scan for quoted string fist, if no good then try unquoted --*/
          if (sscanf(str," '%[^']'%n",strval,&length) != 1)
         // is the space after str," a problem?
    I do not have the experience to tell wether this space at the beginning of the format string is a source of problems. Sadly, I can't find a note on spaces in format strings in the ANSI-C standard. What I remember is my Prof. saying that spaces in format string of scanf and related functions are "deadly".

    Any help is really appreciated.
    Last edited by Sargnagel; 01-24-2003 at 06:23 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This post makes no sense. All the above code is perfectly legal. Here is a bit more on the topic. Having spaces in your scan strings is also fine. You just have to be aware of what you're looking for. I don't see spaces as "deadly".

    In the provided link, pay attention to the "Conversion Speficierrs" section.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    [latest edit]
    Your right, quzah! I've found the problem. I forgot totally that I had to convert the source files from DOS to UNIX format in order to compile them with GCC. And after about 2 months working with GCC alone, I had totally forgotten to convert the files back to DOS format in order to compile them with Borland without such strange errors.
    %%&| happens ...
    [/latest edit]
    This post makes no sense. All the above code is perfectly legal.
    Well, GCC and Borland obviously treat the following source code differently:
    Code:
    sscanf(str,"%i %n", ......);
    Both compile without errors or warnings. With GCC the command line parsing works just as expected but the program compiled with Borland prints out an error message:
    Code:
    C:\cygwin\home\User>program input.txt -calc1 -print yes -nbr 1500 -color off
    
    -nbr 1500
    
         ^^^^ unexpected argument
    But when I remove the space from the format string, the command line interface suddenly works as it did before with GCC and the space.

    [edit]
    A possible explanation may be that the command line is processed differently by the cygwin emulated Unix Shell and the Win2000 "DOS"-Box.
    Hmmm ... but then why does the GCC compiled program work, too, when started from the "DOS"-Box? When compiled with Borland the program doesn't work from neither cygwin shell nor "DOS"-Box.
    I really don't know what's the course of this problem ...
    [/edit]
    Last edited by Sargnagel; 01-25-2003 at 04:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. format specifiers
    By Itanium in forum C# Programming
    Replies: 1
    Last Post: 03-26-2007, 07:31 AM
  2. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  3. wsprintf and format specifiers
    By incognito in forum Windows Programming
    Replies: 2
    Last Post: 01-03-2004, 10:00 PM
  4. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM
  5. format specifiers quick question
    By meltingdude in forum C Programming
    Replies: 2
    Last Post: 06-21-2003, 08:19 AM