file open in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mohamed farouk
    New Member
    • Feb 2008
    • 2

    file open in C

    how to open a file in C ?
    the path of the file is specified by the user
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Have you started this? Where are you stuck? Did you read the location in yet? How are you storing it?

    Comment

    • masterofthebus
      New Member
      • Jan 2008
      • 2

      #3
      files are read as streams, as outputs you can see on std::cout.
      what you need to do is to use fstream. for example, if you will only read the file you should open it with an ifstream

      ifstream input;
      input.open(stri ng path);

      when you finish reading you should close the file.

      There are good sites for this. like cpp reference, just google it

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by masterofthebus
        files are read as streams, as outputs you can see on std::cout.
        what you need to do is to use fstream. for example, if you will only read the file you should open it with an ifstream

        ifstream input;
        input.open(stri ng path);

        when you finish reading you should close the file.

        There are good sites for this. like cpp reference, just google it
        That's C++, not C.

        Comment

        • Simonius
          New Member
          • Feb 2008
          • 47

          #5
          You need to declare a file pointer,
          Then a fopen, you have a few acces methods so just decide which you need (easily googable).

          Comment

          • mohamed farouk
            New Member
            • Feb 2008
            • 2

            #6
            i have a transport stream file & i want to open it & analyze it ,
            but i want to make a program that the user is the one who specifies the file location on the computer
            not
            *f =fopen(C:\\proj ect\\.......... ......)
            i wanna
            printf("Enter the location of the file");
            then after that what should i do ?

            Comment

            • Laharl
              Recognized Expert Contributor
              • Sep 2007
              • 849

              #7
              You'd use scanf to get the user input from command line and set it to a string.

              Comment

              Working...