You are here:

C++/files in c

Advertisement


Question
Hi

i want to learn about file code,i wrote the fallowing code it doesn't have error but doesn't work
could you plz tell tell me what's the matter with it?

and my second question is that when we write:

fp=fopen("c:\\text","r");

we should create the "text" file in c directory?

and if yes.what kind of file we should make in c directory?(notepad,word...)

thanx
Bita

Answer
Bita,

fp=fopen("c:\\text","r");

is not correct because you want c:\\text, or, c:/text.  And, the file *must* exist.  If c:/text doesn't exist, fp will be NULL.

Yes, you must create c:\text and notepad is fine.  Word, only fine if you save as ASCII.  A DOC file isn't a text file.

Bill

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering

©2016 About.com. All rights reserved.