Thread: Overlapping arrays problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    Overlapping arrays problem

    Hi,
    I've run into thi sproblem a few times in my program. I have a number of arrays in a class, and I fill them in order one by one. But once I write to a praticular array the contents get copied at the end of another array. here's a snipet of my code:
    Class deffinition:
    Code:
    class gVars        
    	{
    	public:
    
    		std::vector < CString > vectBP;	
    		std::vector <CString> vectParmSelected;
    		char hEngName[13];
    		char hVersion[13];
    		char EngName[11];
    		int VersionNum;
    
    		gVars()
    		{
    			VersionNum=0;
    			memset(hEngName, 0, sizeof(hEngName));
    			memset(hVersion, 0, sizeof(hVersion));
    			memset(EngName, 0, sizeof(EngName));
    
    		};
    	};
    the main to fill the arrays:
    Code:
    .......................................
    FindWord(inp,"!EICAS_SW_VER", vars.hVersion);
    
    	fprintf(out, ">%s<\n\n", vars.hVersion);
    
    	SkipWS(inp);
    	GetWord(inp,Word);
    
    	vars.VersionNum=atoi(Word);
    
    	fprintf(out, ">%s<\n\n", vars.hVersion);
    	
    	FindWord(inp,"!ENGINE_NAME", vars.hEngName); 
    	SkipWS(inp);
    	fprintf(out, ">%s<\n\n", vars.hVersion);
    
    	GetWord(inp,Word);
    	fprintf(out, ">%s<\n\n", vars.hVersion);
    
    	strcpy(vars.EngName, Word);
    	fprintf(out, ">%s<\n\n", vars.hVersion);
    .........................
    the output:
    Code:
    >!EICAS_SW_VER<
    
    >!EICAS_SW_VER<
    
    >!EICAS_SW_VER<
    
    >!EICAS_SW_VER<
    
    >!EICAS_SW_VER"Engversion"<
    All the strings should be identical.
    Last edited by earth_angel; 07-05-2005 at 06:38 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a problem regarding dynamic memory and arrays
    By Michty in forum C++ Programming
    Replies: 5
    Last Post: 07-26-2006, 01:26 PM
  2. assignment of arrays problem
    By HumbuckeR in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2006, 04:25 PM
  3. Problem with arrays
    By dogbert234 in forum C++ Programming
    Replies: 2
    Last Post: 03-25-2006, 03:06 AM
  4. Problem with character arrays in classes
    By spoketoosoon in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2004, 03:57 AM
  5. Replies: 5
    Last Post: 12-03-2003, 05:47 PM