Re: Reading Text Files



Rafael said:

Barry Schwarz escreveu:
On Tue, 03 Mar 2009 18:44:08 +0000, Flash Gordon
<smap@xxxxxxxxxxxxxxxxx> wrote:

Barry Schwarz wrote:
On Mon, 2 Mar 2009 20:49:20 -0000, "Mike" <gdf@xxxxxxx> wrote:

Hi,

I'm trying to create a C function that will read a text file
but I keep getting fopen() = NULL

I've tried my own code and when that didn't work I tried code
off various websites and they keep giving the same result.

The file was created in notepad, saved as a .txt and contains
only "abcd" without quotes.

Only thing I can think of is that the program doesn't have
rights to access the file....possibly because it's Vista? But
nothing turns up after searching.

The code is written:

FILE *fp;
fp = fopen( "C:\Users\<Username>\Documents\R.txt", "r" );
Did not your compiler generate some mandatory diagnostics on
this line?
What mandatory diagnostic? In C90 those are all just simple
escape sequences invoking undefined behaviour. If gcc is right
then \U has special meaning in C99, but there is every chance
the OP is not using C99.

I was thinking of the one required by footnote 65 in n1256 but I
see that it is not required in C89.


Copy teh document to the root directory (c:\) and give it a try.

That wouldn't fix his problem, which is that he's forgotten to
escape his backslashes.

By the way, what compiler are you using (I dont have your original
post, sorry).

It doesn't matter - the code is equally broken in all C compilers,
because backslashes are escape characters in ISO C.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: pygame music, cant read mp3?
    ... format is to use backslashes as separators, ... escaped in python's regular string literals, ... only because you've been lucky in not having escape characters following ... Notice that the \ gets doubled automatically by python in many ...
    (comp.lang.python)
  • Re: get only filenames and not directory names under a specific path.
    ... > I'm guess maybe it's must do that when it's double quotes. ... but with two exceptions: the escape character itself ... the string delimiter can also be escaped to allow embedded single quotes, ... means that a path with a trailing backslash needs two backslashes there to avoid ...
    (perl.beginners)
  • Re: TR 24731 approved
    ... Can't you just escape all question marks with backslashes, the same way you have to escape quotation marks and backslashes? ...
    (comp.std.c)
  • Re: simple question
    ... Quoting is simpler with $style command substitution. ... escape the inner quotes with backslashes. ... Shell Scripting Recipes: ...
    (comp.unix.shell)
  • Re: Another Printing Question
    ... that backslashes inside string literals must not be escaped in VB.NET. ... Someone suggested that I escape them. ... but that's nonsense for VB.NET -- are you sure you are using ... got me rid of that filenotfound exception at that time. ...
    (microsoft.public.dotnet.languages.vb)