Date: Sun, 17 Jan 1993 15:29 EST From: "Wonkoo Kim, EE, U. of Pittsburgh" Subject: Re: C-language Problem? To: sngattan AT interceptor DOT ksu DOT ksu DOT EDU, djgpp AT sun DOT soe DOT clarkson DOT EDU sngattan AT interceptor DOT ksu DOT ksu DOT EDU (Down and Under) wrotes > I am working on an IBM-PC and an trying to open a file using >the "fopen" command. As long as I open the file in the same directory >where I am running my executable, it works fine. But the moment I >specify a path..it cannot find that file. Here is the complete >description of the problem" > > I am working in c:\ktran\image directory. I want to open >a file in c:\ktran\pgm directory...the filename is "crk1.pgm" > >****Begin part of the code > > char buffer[80]; > buffer = "c:\\ktran\\pgm\\crk1.pgm"; > > inpfile = fopen (buffer,"rb"); Well, there is inconsistency in using char variable of buffer. The declaration "char buffer[80]" assigns some memory address to buffer so that it points to some memory space that can hold 80 chars. buffer = "c:\\ ..." statement will assign another new address to buffer that is different from the address already assigned by char buffer[80]. The new memory space (assigned by "c:\\ ...") may not hold a long string. (Some compilers can allocate a new memory space for this long string, but some cannot. Short string is possibly okay.) The program is clearly wrongly written. So, use strcpy(buffer, "c:\\...\\crk1.pgm"); instead of buffer="c:\\...";. OR, declare buffer with initialization like char buffer[]="c:\\...";. (Using / instead of \\ doesn't solve the problem. \\ is fine under msdos.)