Solved

VC++ 1.52; problems with argc, **argv

Posted on 1998-01-31
1
652 Views
Last Modified: 2012-06-21
I am on Windows NT4.0, but forced to use VC++ 1.52 for an application which uses 16 bit database access programs.  I am attempting to process a list of stock ticker symbols.  When I try this in VC++ 4.0 I can access at least 700 symbols.  When I do it in VC++ 1.52 I can only access 30.  If I try to access more than 30, the program crashes.  It doesn't even get to the line that prints argc-1.

I have never run into this before and I am at a loss as to what is causing it, although I suspect it might have somethng to do with the libraries that are being selected by the project builder.

Here is the simple program I am using for testing:

/*
      sample.cpp
      
      These examples will demonstrate how to use the
      Quotes Plus dll to read all of the price and
      fundamental data that we have.

      The functions automatically open all of the Quote
      Plus files when called, and close the files on exit.

*/

#include <stdio.h>
#include <string.h>


FILE *fp;

void main(int argc, char **argv)
{
      #define LEN 9
      char out[] = "C:\\tmp\\n.p";
      char sym[LEN];
      int i;

      printf ("The number of arguments is %d.\n", argc-1);

      fp = fopen( out, "w" );
      if ( !fp ) {
            printf ("Could not open %s.\n", out);
            return;      // Could not open it.
      } else printf ("Opening %s for writing.\n", out);

      printf ("The output file is %s.\n", out);
 

      while (--argc > 0) {

            strcpy(sym, *++argv);
            i = strlen(sym);
            while (++i < LEN)
                  sym[i] = ' ';
            sym[LEN] = '\0';

            fprintf (fp, "%s\n", sym);
      }

      fclose( fp );

}

Here are the library definitions from the makefile generated by the project builder for this test, except that I replaced mlibcew with mlibcewq in order to access printf:

CFLAGS_D_WEXE = /nologo /W3 /FR /G2 /Zi /D_DEBUG /Od /AM
      /GA /Fd"SAMPLE.PDB"
CFLAGS_R_WEXE = /nologo /W3 /FR /O1 /DNDEBUG /AM /GA
LFLAGS_D_WEXE = /NOLOGO /NOD /PACKC:61440 /STACK:1024
      /ALIGN:16 /ONERROR:NOEXE /CO  
LFLAGS_R_WEXE = /NOLOGO /NOD /PACKC:61440 /STACK:10240
      /ALIGN:16 /ONERROR:NOEXE  
LIBS_D_WEXE = mafxcwd oldnames libw mlibcewq commdlg.lib
      olecli.lib olesvr.lib shell.lib
LIBS_R_WEXE = mafxcw oldnames libw mlibcewq commdlg.lib
      olecli.lib olesvr.lib shell.lib
RCFLAGS = /nologo
RESFLAGS = /nologo

Here are the library definitions from the original program where I first encountered this problem:

CFLAGS_D_WTTY = /nologo /G2 /Zp1 /Mq /W3 /Zi /AL /Od /D
      "_DEBUG" /FR /Fd"SAMPLE.PDB"
CFLAGS_R_WTTY = /nologo /Gs /G2 /Mq /W3 /AM /Ox /D "NDEBUG"
      /FR
LFLAGS_D_WTTY = /NOLOGO /NOD /PACKC:57344 /ALIGN:16
      /ONERROR:NOEXE /CO
LFLAGS_R_WTTY = /NOLOGO /NOD /PACKC:57344 /ALIGN:16
      /ONERROR:NOEXE
LIBS_D_WTTY = lafxcwd llibcewq read11dl.lib oldnames libw
LIBS_R_WTTY = mafxcw mlibcewq oldnames libw read11dl.lib
RCFLAGS = /nologo
RESFLAGS = /nologo

Note that the original makefile was provided by the vendor and maintained unchanged, while the test makefile was built by the project builder and the only change was to replace mlibcew with mlibcewq.  For some reason the project builder assigns mlibcew but mlibcew does not have printf.  I don't understand that either.

If anybody can tell me why this program croaks at the 31st input arg, I would greatly appreciate it.

Bob
0
Comment
Question by:rbp
1 Comment
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 1179756
This is not a VC1.52 vs. 4.0 issue, it's Windows NT vs. MSDOS (i.e. 16-bit environment).  Under MSDOS you can only have a command line of a certain lengthm and I believe that it's 256 or less.  If you go beyond that, the buffer where the command line is stored runs into some other data structures and boom, your program dies.  NT doesn't have this problem.  I'd suggest feeding this quantity of data into your program via another method if you must run on 16-bit Windows.  Write it to a file and have your program read the file.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question