• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

open file problem

#include <stdio.h>

FILE *stream;

void main( void )
{
   int numclosed;

   if((stream=fopen("C:\project\SetWiz.log","r"))== NULL )
      printf( "The file 'data' was not opened\n" );
   else
      printf( "The file 'data' was opened\n" );
}

The file exists in the directory but the program can't open the file.
It seems that use the fopen to open a file, i only can open the file with current directory.
Izzit anyway i can open the file in any directory?
For example:
fopen("C:\project\project2\data.txt") ?
0
cialat
Asked:
cialat
1 Solution
 
Droby10Commented:
it doesn't look like your '\' in your file path variable/parameter for fopen are escaped?
0
 
jkrCommented:
Droby10 is absolutely correct - it should read 'fopen("C:\\project\\SetWiz.log","r")' or 'fopen("C:/project/SetWiz.log","r")'
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now