Solved

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

Posted on 1998-01-31
1
658 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 136
Writing a parser for java language 4 100
Least Squares Curve Fitting 4 131
Creating a Windows C++ program in visual studio 2015 5 24
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

738 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