can't read sequential files

Dave Korn dave.korn@artimi.com
Wed Oct 31 12:41:00 GMT 2007


On 31 October 2007 00:11, zirtik wrote:

> 	int i;
> 	fp = fopen ("phi.txt","r");
> 
> 	for( i = 0; i < 51; i++ ) {
> 		fscanf(fp, "%d\n", &original_phi[i]);
> 	}

> 655 [main] Genetics 3012 _cygtls::handle_exceptions: Exception:
> STATUS_ACCESS_VIOLATION
> 2540 [main] Genetics 3012 open_stackdumpfile: Dumping stack trace to
> Genetics.exe.stackdump

> if (fp==NULL)
> {
>    printf("error, NULL pointer!\n");
>    return(1);
> }
> 
> and it is always NULL. 

  You should also print out the value of 'errno' here, it's the global
variable that holds the code for the last error from C library functions.

> I put the "phi.txt" in the same directory as the
> executable so it is in:
> 
> ....\ProjectFolder\Debug
> 
> folder as well as in
> 
> ....\ProjectFolder\src
> 
> folder. I still keep getting the same error.

  It would tell us a lot if we knew whether errno was equal to ENOENT or
EACCES.

> I added the current directory
> "." to the PATH but it didn't help. 

  Nope, it wouldn't make a difference.  PATH is only used by the shell when
searching for commands; it isn't used when you're calling fopen.  For fopen,
you must provide the exact path to the file, or the file must be in the cwd
(current directory) when your program is running.

> This code used to run on another PC with
> Eclipse and cygwin again but this is the first time I am having problems
> with it on a different machine. Any help would be greatly appreciated.

  I don't use eclipse myself, but I'd guess there's a setting somewhere for
what the current directory should be when it launches the executable.  Make
sure your text file is in that directory, or change the setting so it points
at the debug/release folder where you already put the text file.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list