Thread: fopen help

  1. #1
    Registered User
    Join Date
    Mar 2008

    fopen help

    have specify a correct path to the text file. why isit printing cant open file
    #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");
            return 0;

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You should escape literal backslashes in string literals. Try:
    FILE *myfile = fopen("c:\\Users\\norphos\\test.txt","r");
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2008
    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, 05:28 AM
  2. fopen help.
    By chriscolden in forum C Programming
    Replies: 17
    Last Post: 01-13-2006, 05:27 AM
  3. problem with fopen command
    By emon in forum C Programming
    Replies: 2
    Last Post: 03-11-2004, 11:11 PM
  4. fopen() and open()
    By Encrypted in forum C Programming
    Replies: 8
    Last Post: 02-09-2003, 03:57 PM
  5. fopen vs open
    By rotis23 in forum Linux Programming
    Replies: 5
    Last Post: 12-10-2002, 01:30 PM
Website Security Test