FILE input output in C

This is a discussion on FILE input output in C within the C Programming forums, part of the General Programming Boards category; this is my code which i wrote in linux.... i know its silly but just want to know whats the ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    4

    Question FILE input output in C

    this is my code which i wrote in linux....
    i know its silly but just want to know whats the default directory that the files input and output are created......
    what if i want to give my own path say C drive .....then what should i write in the path.....
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    void main()
    {
      FILE *fp,*fp1;
      fp=fopen("input","r");
      fp1=fopen("output","w");
      int *a,i=0;
      fscanf(fp,"%d",&i);
    
      while(!feof(fp))
      {
        fprintf(fp1,"%d ",i);
        fscanf(fp,"%d",&i);
      }
    
      fclose(fp);
      fclose(fp1);
    }

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    978
    If the filename is a relative path (that is, if it doesn't start with a / character) then it opens relative to the current directory. In this case, that means "output" will be created in whatever directory you were in when you ran the program.

    Linux doesn't have a concept of a "C drive", but you can open a path as you would anywhere else, e.g.:
    Code:
    fopen("/home/user/file", "r");

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    I think it will take time to adjust and work on Linux os......
    Anyways,Thanks a lot for the info!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ File Input Output VS C file Input Output
    By forumuser in forum C++ Programming
    Replies: 1
    Last Post: 09-30-2009, 06:46 AM
  2. File Input/Output
    By Mornic_Programm in forum C++ Programming
    Replies: 8
    Last Post: 05-30-2005, 01:11 PM
  3. file input and output
    By isaac in forum C Programming
    Replies: 3
    Last Post: 06-04-2002, 04:41 PM
  4. File Input / Output Help?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-18-2002, 10:20 AM
  5. file input/output
    By Sean Gilbride in forum C Programming
    Replies: 3
    Last Post: 02-10-2002, 08:59 PM

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