problem w/ class methods

This is a discussion on problem w/ class methods within the C++ Programming forums, part of the General Programming Boards category; Hey, I'm trying to write a class to process strings. Here it is: Code: class FileBrowse { private: static CString ...

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

    problem w/ class methods

    Hey,

    I'm trying to write a class to process strings. Here it is:
    Code:
    class FileBrowse
    {
    private:
    	static CString fpath;
    
    public:
    	static CString GetFPath()
    	{
    		return fpath;
    	}
    
    	CString MakeName(CString rfname)
    	{
    		char temp[8];
    		int index, indexn, i, k=0;
    		CString nfname;
    
    		index = rfname.Find('/');
    
    		for(i=(index+1); i<(index+8); i++)
    		{
    			temp[k] = rfname[i];
    			k++;
    		}
    		temp[k] = '\0';
    
    		nfname = fpath;
    
    		indexn = nfname.ReverseFind(']');
    
    		nfname.SetAt(indexn, '.');
    
    		nfname = nfname + temp + ']';
    		
    		return nfname;
    	}
    };
    CString FileBrowse::fpath = "recording:[000000]";
    I call the methods in a loop in the main function where the class is instanciated, but at some point in the loop it stops working with an Access Violation error. I print them in an FTP file browsing loop:
    Code:
    	while (bWorking)
        {
    		bWorking = finder.FindNextFile();
    
    		rfname = finder.GetFilePath();
    
    		fprintf(out, ">%s<\n", rfname);
    
    		nfname = ConnectFile.MakeName(rfname);
    
    		fprintf(out, "\t\t>%s<\n", nfname);
    
    		rfname.Empty();
    		nfname.Empty();
    }
    Here's the ourput:
    Code:
    >NEW_RECORDING_ROOT:[000000]/FCP0002.DIR;1            1/50         11-APR-2005 16:52:14  [SYSTEM]               (,RWED,RWED,R)<
    		>recording:[000000.FCP0002]<
    >NEW_RECORDING_ROOT:[000000]/FDAC000.DIR;1            1/50         16-AUG-2005 08:11:00  [SYSTEM]               (,RWED,RWED,R)<
    		>recording:[000000.FDAC000]<
    >NEW_RECORDING_ROOT:[000000]/FDAC001.DIR;1
    It doesn't print the whole string it stops in the middle of it.
    what is missing/
    Everything is relative...

  2. #2
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Can you provide a list of the strings that are being processed so that I can test your code?
    Just because I don't care doesn't mean I don't understand.

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I'm reading them from an FTP server. and it seems to only give an error when I run it in debug mode. I get an access violation error.
    I'm still trying to figure where it fails.
    Last edited by earth_angel; 08-29-2005 at 01:44 PM.
    Everything is relative...

  4. #4
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    The debugger gets stuck at rfname.Empty() line. I can't move past that point when it goes through the loop third time around.
    Everything is relative...

  5. #5
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    The debugger gets stuck at rfname.Empty() line.
    Sounds like your trampling memory somewhere, but I'm no expert with CString, so I won't hazard a guess.
    Just because I don't care doesn't mean I don't understand.

  6. #6
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I've taken a look at the code a bit and I can't find where the memory is leaking. Also, the print statement do nothing now. The ourput file contains nothing after the function runs. Would a memory leak affect the printing?
    In debug mode I get an access violation at the closing bracket of a function. It says NTDLL.... Access Violation.
    The function that fails is here:
    Code:
    FileBrowse::ResetFpath("recording:[000000]");
    
    	int radioState =0; 
    	char location = 'N';
    	char buffer[100];
    	FileBrowse ConnectFile;
    	CString localfile;
    
    	CButton* pRadio = (CButton*)GetDlgItem(IDR_TO); 
    	radioState = pRadio->GetCheck();
    
    	if(radioState)
    		location = 'T';
    
    	radioState = 0;
    
    	pRadio = (CButton*)GetDlgItem(IDR_MO); 
    	radioState = pRadio->GetCheck();
    
    	if(radioState)
    		location = 'M';
    
    	radioState = 0;
    
    	pRadio = (CButton*)GetDlgItem(IDR_LO); 
    	radioState = pRadio->GetCheck();
    
    	if(radioState)
    		location = 'L';
    	
    	CInternetSession isession;
    
    	CFtpConnection* pConnect;
    	CString Server;
    
    	InBAF::SetLocation(location);
    	InBAF::SetServerName(location);
    	Server = InBAF::GetServerName();
    
    	pConnect = isession.GetFtpConnection(_T(Server), "USER");
    	
    	pConnect->SetCurrentDirectory("recording:[000000]");
    	
    			FILE *out = fopen("H:\\GUI\\testInet-main.txt", "w");
    
    	CFtpFileFind finder(pConnect);
    
    	// Find  the first file 
    	BOOL bWorking = finder.FindFile(NULL);
    	CString rfname, nfname;
    	
    	// Go through the rest of the directory and designate files.
    	while (bWorking)
        {
    		bWorking = finder.FindNextFile();
    
    		rfname = finder.GetFilePath();
    
    		if (strstr(rfname, ".LSH"))
    		{
    			nfname = ConnectFile.MakeName(rfname);
    			fprintf(out, "\t\t\tSub: %s\n", nfname);
    		}
    		else if(strstr(rfname, ".DIR"))
    		{
    			nfname = ConnectFile.MakeName(rfname);
    			fprintf(out, "\t\t\tMain: %s\n", nfname);
    		}
    
    		rfname.Empty();
    		nfname.Empty();
    
    	}
    When I step to the red bracket I get the error.
    Last edited by earth_angel; 08-30-2005 at 08:08 AM.
    Everything is relative...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21