Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
FILE *fp;
fp = fopen(ImeFajla->Text.c_str(),"a+");
if (fp == NULL)
    Label1->Caption="Neuspjesno ovaranje fajla...";
Label1->Caption="Ucitan sadrzaj fajla";
char s[101];
while(fgets(s,100,fp) != NULL)         
// *problem Project Project11.exe raised exception class EAccessViolation 
// with message 'Access violation at address 3286ED28 in module 
// 'CC3280MT.DLL'. Read of address F85BE2DC'.
{
    ListBox1->Items->Add(s);
    n++;
}
fclose(fp);
}
Posted
Updated 24-Jan-10 6:04am
v3

Is fp NULL?

While you do check if fp is NULL, you also continue and attempt to use it even if it is NULL. This is not appropriate.
 
Share this answer
 
stavor wrote:
if (fp == NULL)
Label1->Caption="Neuspjesno ovaranje fajla...";
Label1->Caption="Ucitan sadrzaj fajla";


Show an error or something, and return control from the function if fopen doesn't return a valid file pointer.

Like the other poster said, you're checking for this error condition, but are ignoring any possible error that could occur!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900