Click here to Skip to main content
16,004,192 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
Mark Salsbery26-Nov-07 6:15
Mark Salsbery26-Nov-07 6:15 
GeneralRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
mrby12326-Nov-07 6:32
mrby12326-Nov-07 6:32 
AnswerRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
Luc Pattyn26-Nov-07 6:33
sitebuilderLuc Pattyn26-Nov-07 6:33 
GeneralRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
mrby12326-Nov-07 6:52
mrby12326-Nov-07 6:52 
GeneralRe: fclose(f_ptr2) - "Access Violation or memery can not be read" [modified] Pin
Luc Pattyn26-Nov-07 7:03
sitebuilderLuc Pattyn26-Nov-07 7:03 
GeneralRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
David Crow26-Nov-07 7:22
David Crow26-Nov-07 7:22 
GeneralRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
Luc Pattyn26-Nov-07 7:39
sitebuilderLuc Pattyn26-Nov-07 7:39 
QuestionRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
David Crow26-Nov-07 7:18
David Crow26-Nov-07 7:18 
While it (probably) has nothing to do with your problem, I'd offer:

1) Don't post commented-out code. It just makes that much more for us to have to read/ignore.
2) Since you are using MFC, why not take advantage of CStdioFile, AfxMessagBox(), and CFileFind?

That said, do the first 2-4 "columns" in your input file contain more than 14 characters? If so, buffer will not hold them all.

If there are more than 2000 files in the folder pointed to by DirSpec, you'll have obvious trouble.

Your very last for() loop is using ii and II. Is that intentional?

mrby123 wrote:
DirSpec = (LPTSTR) malloc (BUFSIZE);
DirSpec=TEXT("*.txt");


The address assigned to DirSpec (from malloc()) has been changed, and a subsequent call to free() would fail.

Consider:

CStringArray fileNames;        
CFileFind fileFind;
 
BOOL bFound = fileFind.FindFile("*.txt");
while (bFound)
{
    bFound = fileFind.FindNextFile();
    fileNames.Add(fileFind.GetFilePath());
}
 
fileFind.Close();
 
for (int ii = 0; ii < fileNames.GetSize(); ii++)
{
    CString fileName = fileNames.GetAt(ii);
 
    CStdioFile fileIn;        
    if (fileIn.Open(fileName, CFile::modeRead))
    {
        CString line;
        fileIn.ReadString(line);
 
        // parse line here
         
        fileIn.Close();
    }
}
 
CStdioFile fileOut;
if (fileOut.Open(m_outputFileName, CFile::modeWrite))
{
    CString str;
 
    str.Format("%d\n", fileNames.GetSize());
    fileOut.WriteString(str);
    fileOut.WriteString(str);
 	 
    fileOut.WriteString("fineName  Easting(m)  Northing(m)  elv(m)\n");
 
    for (int ii = 0; ii < fileNames.GetSize(); ii++)
    {
        CString fileName = fileNames.GetAt(ii);
 
        str.Format("%s  %f  %f  %f\n", fileName, east[ii], north[ii], elv[ii]);
        fileOut.WriteString(str);
    }
 
    fileOut.Close();
}



"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne


AnswerRe: fclose(f_ptr2) - &amp;amp;amp;amp;quot;Access Violation or memery can not be read&amp;amp;amp;amp;quot; Pin
Luc Pattyn26-Nov-07 7:48
sitebuilderLuc Pattyn26-Nov-07 7:48 
AnswerRe: fclose(f_ptr2) - &amp;amp;amp;amp;amp;amp;amp;amp;quot;Access Violation or memery can not be read&amp;amp;amp;amp;amp;amp;amp;amp;quot; Pin
mrby12326-Nov-07 8:12
mrby12326-Nov-07 8:12 
GeneralRe: fclose(f_ptr2) - &amp;amp;amp;amp;amp;amp;amp;amp;quot;Access Violation or memery can not be read&amp;amp;amp;amp;amp;amp;amp;amp;quot; Pin
David Crow26-Nov-07 10:37
David Crow26-Nov-07 10:37 
GeneralRe: fclose(f_ptr2) - &amp;amp;amp;amp;amp;amp;amp;quot;Access Violation or memery can not be read&amp;amp;amp;amp;amp;amp;amp;quot; Pin
Mark Salsbery26-Nov-07 13:23
Mark Salsbery26-Nov-07 13:23 
GeneralRe: fclose(f_ptr2) - &amp;amp;amp;amp;amp;amp;amp;quot;Access Violation or memery can not be read&amp;amp;amp;amp;amp;amp;amp;quot; Pin
David Crow26-Nov-07 15:46
David Crow26-Nov-07 15:46 
GeneralRe: fclose(f_ptr2) - &amp;amp;quot;Access Violation or memery can not be read&amp;amp;quot; Pin
Sunil Shindekar26-Nov-07 23:47
Sunil Shindekar26-Nov-07 23:47 
GeneralRe: fclose(f_ptr2) - &amp;amp;quot;Access Violation or memery can not be read&amp;amp;quot; Pin
David Crow27-Nov-07 3:46
David Crow27-Nov-07 3:46 
GeneralRe: fclose(f_ptr2) - &amp;amp;quot;Access Violation or memery can not be read&amp;amp;quot; Pin
Sunil Shindekar27-Nov-07 21:06
Sunil Shindekar27-Nov-07 21:06 
QuestionRe: fclose(f_ptr2) - &amp;amp;quot;Access Violation or memery can not be read&amp;amp;quot; Pin
David Crow28-Nov-07 2:32
David Crow28-Nov-07 2:32 
Questionfclose(f_ptr2) - "Access Violation or memery can not be read" Pin
mrby12326-Nov-07 5:59
mrby12326-Nov-07 5:59 
AnswerRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
Mark Salsbery26-Nov-07 6:05
Mark Salsbery26-Nov-07 6:05 
GeneralRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
mrby12326-Nov-07 6:36
mrby12326-Nov-07 6:36 
QuestionRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
David Crow26-Nov-07 7:12
David Crow26-Nov-07 7:12 
AnswerRe: fclose(f_ptr2) - "Access Violation or memery can not be read" Pin
mrby12326-Nov-07 7:30
mrby12326-Nov-07 7:30 
QuestionLooking for a Gantt chart control Pin
Interrobang26-Nov-07 4:44
Interrobang26-Nov-07 4:44 
Questioncompile error when make a wchar_t conversion Pin
George_George26-Nov-07 3:53
George_George26-Nov-07 3:53 
AnswerRe: compile error when make a wchar_t conversion Pin
CPallini26-Nov-07 4:04
mveCPallini26-Nov-07 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.