file I/O

This is a discussion on file I/O within the C Programming forums, part of the General Programming Boards category; hi i have a question about c programing file I/O i did this text file "term" and saved it at ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    Question file I/O

    hi

    i have a question about c programing file I/O

    i did this text file "term" and saved it at desktop

    C:\Users\MYNAME\Desktop\term.txt


    i wrote this code

    Code:
    #include <stdio.h>
    
    int main ()
    {
    FILE *open;
    open = fopen("C:\\Users\\MYNAME\\Desktop\term.txt" , "r");
    getchar ();
    }
    when i compile the program and run nothing happens, can some one help me.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Since your program does nothing by design, that's what you would expect. fopen doesn't open notepad or anything, it merely allows your program to access the contents of the file, should you so desire.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    reply

    so how can i open the file, or i can't do that in C

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    Code:
    #include <stdio.h>
    #define array_size 300
    #define FNAME "C:\\Users\\MYNAME\\Desktop\term.txt"
    int main ()
    {  
          FILE *fptr;
         char buffer[array_size];//to save in the lines as longest as it can be
         fptr = fopen(FNAME, "r");
         if(fptr==NULL)
           exit(1);
    while(fgets(buffer,sizeof buffer,fptr)!=NULL)
             fputs(buffer,stdout);
    return getchar();
    }

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    note that all '\' chars should be escaped in the file name
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    How about working on the indentation, as well?
    No to mention closing the file after it's finished!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 04:56 AM

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