Solved

open file problem

Posted on 2002-07-25
2
184 Views
Last Modified: 2010-04-15
#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
Comment
Question by:cialat
2 Comments
 
LVL 5

Accepted Solution

by:
Droby10 earned 60 total points
ID: 7177796
it doesn't look like your '\' in your file path variable/parameter for fopen are escaped?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7177935
Droby10 is absolutely correct - it should read 'fopen("C:\\project\\SetWiz.log","r")' or 'fopen("C:/project/SetWiz.log","r")'
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question