Advertisement

Bafflement

Started by February 11, 2001 07:23 PM
3 comments, last by benjamin bunny 23 years, 11 months ago
I have the following program:
  
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>

int main(int argc, char * argv[ ])
{
	FILE * fle;

	int a;

	if( (fle  = fopen( "blah.txt", "rb" )) == NULL )
	{
		printf("Error opening file\n");

	}
	else 
	{
		printf("File opened successfully");
		fclose(fle);
	}
	getch();
	
}
  
When I double-click the program''s icon to open it it loads the file fine, yet when I drag something onto the icon it returns "Error opening file". Can somebody please explain why? http://www.geocities.com/ben32768

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Instead of "Blah.txt" check to see if argc>1 and then use argv[1] as the file name. It might work...
Advertisement
I don''t want it to load argv[1]. I just want it to load "blah.txt" for now.

http://www.geocities.com/ben32768

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

If the file you''re dragging onto it is in a different dir than blah.txt, maybe it''s starting the program in that dir.
Quantum probably has it right.

If you actually checked the error code you would probably get more info. The error code will be in the global variable "errno". Your docs will be able to tell you what a given error code means. You can even use perror() to print a string for the error.

-Mike
-Mike

This topic is closed to new replies.

Advertisement