Thread: error opening the file...

  1. #16
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    This is really crazy

    I just created a new file with name rr.txt and it opened. Then i tried with the older file names (that were creating a problem those opened as well).

    Finally able to see the output

    File opened successfully
    1 49
    2 50
    3 51
    123
    Now closing the file
    ExitingPress any key to continue . . .


    But this is really crazy stuff :-(

    @nonoob

    Thanks for the idea of including errno in the file. I didnt knew about it.

  2. #17
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    If you are going for more fancier error interpretation you might want to a general error message generator... Especially use the constants that are predefined instead of hard coding "2", etc.
    Code:
    void check_cause(void) {
    printf("Cause: ");
    switch (errno) {
    case ENOENT:
    	printf("No such file or directory.\n");
    	break;
    case EACCES:
    	printf("Permission denied.\n");
    	break;
    case EINVAL:
    	printf("Invalid argument.\n");
    	break;
    case EMFILE:
    	printf("Too many open files.\n");
    	break;
    default:
    	printf("Error Code %d\n", errno);
    	break;
    	}
    }
    But have a look inside errno.h so see which conditions may possibly apply to your situation.

    I don't know what to tell you about "numbers.txt" not working whereas "rr.txt" does. It's impossible.
    Last edited by nonoob; 07-27-2009 at 03:30 PM.

  3. #18
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    Quote Originally Posted by crowe View Post
    Don't you have to escape the spaces in file paths in Windows? IE:

    Code:
    file = fopen("C:/Documents\ and\ Settings/ROHAN/Desktop/numbers.txt","r");
    Been a while since I actually hard coded a file path, though, so I may be wrong.
    Not on Windows, no.

    Code:
    file = fopen("C:/Documents and Settings/ROHAN/Desktop/numbers.txt","r");
    
    or
    file = fopen("C:\\Documents and Settings\\ROHAN\\Destkop\\numbers.txt","r");
    wipe on -
    A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.
    - wipe off

  4. #19
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quote Originally Posted by crowe View Post
    Don't you have to escape the spaces in file paths in Windows? IE:

    Code:
    file = fopen("C:/Documents\ and\ Settings/ROHAN/Desktop/numbers.txt","r");
    Been a while since I actually hard coded a file path, though, so I may be wrong.
    Not in a C string you don't. In Ubuntu or Linux command line, such as for changeing directory "cd" command, then yeah.

  5. #20
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    Code:
    int myatoi(const char *str)
    {
    	int result = 0;
    
    	while(isdigit(*str))
    	{
    		result *= 10;
    		result += *str - '0';
    		//printf("\n%c \t%d", *str, *str);
    		str++;
    	}
                    printf("%d\n", result);
    	return result;
    }
    I think your code is working right... your output is just a little misleading.
    wipe on -
    A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.
    - wipe off

  6. #21
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by crowe View Post
    Don't you have to escape the spaces in file paths in Windows?
    No. Only the command interpreter requires that.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM