how to read .txt file in linux c code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bswapnil
    New Member
    • Sep 2007
    • 6

    how to read .txt file in linux c code

    hi.....
    i m doinn 1 Dimensional DCT in C. I m New to UNIX so can anybody help me to do this program in unix using C code.i hav one text file as an input which contain 8 numbers as an input.so pls give me code or some link as early as possible.



    thnxx in advance.....
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Google "C file I/O". This is not really a *nix question, as the file opening/closing/reading code is not platform specific.

    Comment

    • ashitpro
      Recognized Expert Contributor
      • Aug 2007
      • 542

      #3
      Originally posted by Bswapnil
      hi.....
      i m doinn 1 Dimensional DCT in C. I m New to UNIX so can anybody help me to do this program in unix using C code.i hav one text file as an input which contain 8 numbers as an input.so pls give me code or some link as early as possible.



      thnxx in advance.....
      You are new to Unix, thats fine
      But you know C I guess.
      Just write your code in some c file say test.c.
      You'll face the problem that which files to include.
      For example. for opening your text file you'll use fopen
      then just do 'man 2 fopen'. this will show you the list of files to include for this system call.
      Compile your code by following command:
      gcc -o test.c test
      if you get any error then solve it or I am here to help you.
      then run your binary as:
      ./test
      You can write your code using vi editor or any thing else you like.

      Comment

      • Bswapnil
        New Member
        • Sep 2007
        • 6

        #4
        Originally posted by Laharl
        Google "C file I/O". This is not really a *nix question, as the file opening/closing/reading code is not platform specific.



        thnxx. i thought there are some other methods of file operations in unix but these are all same like in windows.......t hnxx for ur help...........


        and are there any editor execpt vi editor to run a c code in unix just like,turbo c,dev-cpp for windows........



        pls reply....



        thnxx in advance.....

        Comment

        • Bswapnil
          New Member
          • Sep 2007
          • 6

          #5
          Originally posted by ashitpro
          You are new to Unix, thats fine
          But you know C I guess.
          Just write your code in some c file say test.c.
          You'll face the problem that which files to include.
          For example. for opening your text file you'll use fopen
          then just do 'man 2 fopen'. this will show you the list of files to include for this system call.
          Compile your code by following command:
          gcc -o test.c test
          if you get any error then solve it or I am here to help you.
          then run your binary as:
          ./test
          You can write your code using vi editor or any thing else you like.





          thnxx.......but man 2 fopen is not working on my pc.but now i m able to read txt file thnxx for tat.but give me list of some diffrent editors which are used for writing c code.....




          thnxx in advance.....


          waiting for ur reply.....

          Comment

          • ashitpro
            Recognized Expert Contributor
            • Aug 2007
            • 542

            #6
            Originally posted by Bswapnil
            thnxx. i thought there are some other methods of file operations in unix but these are all same like in windows.......t hnxx for ur help...........


            and are there any editor execpt vi editor to run a c code in unix just like,turbo c,dev-cpp for windows........



            pls reply....



            thnxx in advance.....

            vi is just an editor, like notepad in windows.
            It is not IDE like turbo c where you can execute the code.
            You can use other editors like 'nano','gedit'.

            I suggest you 'fopen' because you were from windows platform.
            There are standard POSIX compliant system calls on linux/unix like open,read,close ,write etc.
            including stdio.h alone can bring the support for fopen.
            You can use open,read,close ,write etc. sys calls by including following files.
            sys/types.h,sys/stat.h,fcntl.h

            Happy Coding.....

            Comment

            Working...