[comp.lang.c] 2 questions

bonak%cs.uiowa.edu@RELAY.CS.NET (Esmail Bonakdarian) (08/28/87)

I am using Turbo C and have the following problem trying to
open a file in a program: 


   if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )
     { fprintf(stderr, "Input file HELPFILE not found.");
       exit(1);
     }

always results in the error message. It seems that I can't specify
a path along with the file name. I have no problems when I just use
"helpfile" 

   if ( (infile = fopen("helpfile", "r")) == NULL )
     { fprintf(stderr, "Input file HELPFILE not found.");
       exit(1);
     }

alone and execute the program in the same directory as the
helpfile. Is there a way to specify the location of a file in some
(other) directory? I'd like to be able to specify a file in a directory
other than the current one.

Also does anybody know a way of getting MS-DOS to use the return value of
an exit(value) in a program?  I.e. I'd like to know (at a DOS level)
whether a program terminated with exit(0) or exit(1).

thanks in advance for any info.

esmail

francus@cheshire.columbia.edu (Yoseff Francus) (08/28/87)

In article <9034@brl-adm.ARPA> bonak%cs.uiowa.edu@RELAY.CS.NET (Esmail Bonakdarian) writes:
>I am using Turbo C and have the following problem trying to
>open a file in a program: 
>
>
>   if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )
>     { fprintf(stderr, "Input file HELPFILE not found.");
>       exit(1);
>     }
>
try using \\ in for the pathname:
   if ( (infile = fopen("c:\\temp\\helpfile", "r")) == NULL )

>esmail




******************************************************************
yf
In Xanadu did Kubla Khan a stately pleasure dome decree
But only if the NFL to a franchise would agree.

ARPA: francus@cs.columbia.edu
UUCP: seismo!columbia!francus

schung@cory.Berkeley.EDU (Stephen the Greatest) (08/28/87)

In article <9034@brl-adm.ARPA> bonak%cs.uiowa.edu@RELAY.CS.NET (Esmail Bonakdarian) writes:
>   if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )
>           ...

Read the manual.

Classic error: \t = tab, not '\''t', and \h = god knows what.

Fix: if ( (infile = fopen("c:\\temp\\helpfile", "r")) == NULL)

Hope this helps.  This common error is forewarned in the manual.

- Stephen

mrd@sun.mcs.clarkson.EDU (Michael R. DeCorte) (08/28/87)

   Date:         Thu, 27 Aug 87 10:17:28 CDT
   Reply-To: Info-C@brl.arpa
   Sender: Info-C List <INFO-C@ndsuvm1.bitnet>
   From: Esmail Bonakdarian <bonak%cs.uiowa.edu@relay.cs.net>
   Comments: To: INFO-C@BRL.ARPA

   I am using Turbo C and have the following problem trying to
   open a file in a program:


      if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )
	{ fprintf(stderr, "Input file HELPFILE not found.");
	  exit(1);
	}

 try
	...stuff..."c:\\temp\\helpfile"....stuff

see page 132 of the user's guide

dhesi@bsu-cs.UUCP (Rahul Dhesi) (08/29/87)

In article <3432@zen.berkeley.edu> schung@cory.Berkeley.EDU.UUCP writes:
>
>Classic error: \t = tab, not '\''t', and \h = god knows what.
>
>Fix: if ( (infile = fopen("c:\\temp\\helpfile", "r")) == NULL)

I heartily recommend:

#define   HELPFILE "/temp/helpfile"   /* note forward slashes */

     if ( (infile = fopen(HELPFILE, "r")) == NULL)

It works, it looks nicer, it's easier to modify, and it's easier to
port to other operating systems, especially the **IX family.
-- 
Rahul Dhesi         UUCP:  {ihnp4,seismo}!{iuvax,pur-ee}!bsu-cs!dhesi

lmiller@venera.isi.edu.UUCP (08/29/87)

In article <9034@brl-adm.ARPA> bonak%cs.uiowa.edu@RELAY.CS.NET (Esmail Bonakdarian) writes:
> I am using Turbo C and have the following problem trying to open a file
> in a program: 
>
>   if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )
>     { fprintf(stderr, "Input file HELPFILE not found.");
>       exit(1);
>     }
>always results in the error message. It seems that I can't specify
>a path along with the file name.

Paths in DOS include a BACKSLASH, which you need to quote with an additional
backslash.  Try this:

   if ( (infile = fopen("c:\\temp\\helpfile", "r")) == NULL )

Larry Miller
USC/ISI
lmiller@venera.isi.edu (no uucp)

zentrale@rmi.UUCP (08/30/87)

In article <9034@brl-adm.ARPA> bonak%cs.uiowa.edu@RELAY.CS.NET (Esmail Bonakdarian) writes:
: I am using Turbo C and have the following problem trying to
: open a file in a program: 
: 
: 
:    if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )

      try: infile = fopen("c:/temp/helpfile", "r")
      or : infile = fopen("c:\\temp\\helpfile", "r")

Turbo C Users Guide p. 132

: 
: Also does anybody know a way of getting MS-DOS to use the return value of
: an exit(value) in a program?  I.e. I'd like to know (at a DOS level)
: whether a program terminated with exit(0) or exit(1).

use "if errorlevel x goto ..." (highest first!)

: 
: thanks in advance for any info.
: 
: esmail

Wolfgang

av@utacs.UUCP (08/31/87)

In article <9034@brl-adm.ARPA> bonak%cs.uiowa.edu@RELAY.CS.NET (Esmail Bonakdarian) writes:
>I am using Turbo C and have the following problem trying to
>open a file in a program: 
>
>
>   if ( (infile = fopen("c:\temp\helpfile", "r")) == NULL )
>     { fprintf(stderr, "Input file HELPFILE not found.");
>       exit(1);
>     }
>
>always results in the error message. It seems that I can't specify
>a path along with the file name. I have no problems when I just use

I know, you are going to get hundreds of answers, but me too...

In C, \ is an escape character, so \t means <TAB> character and so on.
So, use

	fopen("c:\\temp\\helpfile", "r"))

I remember, that MSDOS can also handle paths with '/' character in
open-command. (That is, when there is confusion between file name and
option)

---------
Arto Viitanen
University Of Tampere, Department of Computer Science
P.O.Box 607
SF-33101 TAMPERE
FINLAND

av@utacs.uta.fi