fopen help

This is a discussion on fopen help within the C Programming forums, part of the General Programming Boards category; have specify a correct path to the text file. why isit printing cant open file Code: #include <stdio.h> #include <string.h> ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    19

    fopen help

    have specify a correct path to the text file. why isit printing cant open file
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main()
    {
    	FILE *myfile = fopen("c:\Users\norphos\test.txt","r");
    	if(myfile == NULL)
    		printf("cant open file\n");
    	else
    		printf("sucessful");
    
            return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,302
    You should escape literal backslashes in string literals. Try:
    Code:
    FILE *myfile = fopen("c:\\Users\\norphos\\test.txt","r");
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    great thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with stat() and fopen()
    By movl0x1 in forum C Programming
    Replies: 6
    Last Post: 07-25-2007, 06:28 AM
  2. fopen help.
    By chriscolden in forum C Programming
    Replies: 17
    Last Post: 01-13-2006, 06:27 AM
  3. problem with fopen command
    By emon in forum C Programming
    Replies: 2
    Last Post: 03-12-2004, 12:11 AM
  4. fopen() and open()
    By Encrypted in forum C Programming
    Replies: 8
    Last Post: 02-09-2003, 04:57 PM
  5. fopen vs open
    By rotis23 in forum Linux Programming
    Replies: 5
    Last Post: 12-10-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21