I just tested because i'll need soon the fopen function...
Im using Visual C++ and i made a txt file in the root (didn't work so also tried to put in the source folder.. didn't work either)

the text file's name is: Keywords.txt

I tried this:

fopen("Keywords", "r");

didn't work so also tried this:

fopen("Keywords.txt", "r");

and of course, didn't work either...

Thanks.

Recommended Answers

All 9 Replies

You need to assign the address that fopen() returns to your FILE * (pointer).

FILE *fp;

fp = fopen("Keywords.txt", "rt");

if(fp == NULL) {
   printf("\nError opening file\n");
   return 0;
}

Try: fp = fopen("C:\\path\\to\\file\\Keywords.txt", "r");

Nothing Worked :(

You might post the code that is not working (?).

commented: That would have been the smart thing to do, you would think. +8

Nothing Worked :(

Oh, it will work - but you have the file you're trying to open, in the wrong directory, or an IDE set up problem.

Look into your help files on Debug and Release versions, and find out what directory your IDE is really running your program, from. You have project settings (default probably), that should be able to show you.

I've changed it's location and didn't help..
Although I'd be happy if you'll explain to me what's IDE and how to use it.

In what environment are you programming in ? In fact an IDE is Integrated Development Environment. Like you have for C++ such as turbo C++(quite old though), CodeBlocks, Dev C++ etc..
I guess you are using Visual Studio. if you can share code or version iformation, may be we can help you better.

In what environment are you programming in ? In fact an IDE is Integrated Development Environment. Like you have for C++ such as turbo C++(quite old though), CodeBlocks, Dev C++ etc..
I guess you are using Visual Studio. if you can share code or version iformation, may be we can help you better.

Microsoft Visual C# 2008 Express Edition with SP1 - ENU

> Im using Visual C++
...
> Microsoft Visual C# 2008 Express Edition
One of these is a typo surely?

> fopen("Keywords.txt", "r");
In windows explorer, do you have the "helpful" feature of "hide extensions for known file types" turned on?

Actually, it's of no use at all to anyone with any computer skill.
What you'll probably find is your file is really called "keywords.txt.txt".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.