Output Text File

This is a discussion on Output Text File within the C Programming forums, part of the General Programming Boards category; hello i was wondering how would i take what i input on my keyboard into a text docoument here is ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    8

    Output Text File

    hello i was wondering how would i take what i input on my keyboard into a text docoument here is what i got so far

    Code:
    #include <stdio.h>
    
    /* copy input to output; 1st version */
    main()
    {
          int c;
          
          c = getchar ();
          while (c != EOF) {
                putchar(c);
                c = getchar();
          }
    }
    *EDIT*
    i want the putchar(c) to be what inserted into the text doc
    Last edited by ne0x; 06-09-2005 at 04:32 PM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Use fopen() to open the file and then use fputc() instead of putchar().
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    ok i tried this
    Code:
    #include <stdio.h>
    
    /* copy input to output; 4st version */
    main()
    {
          fopen("c:/output.txt", "w");
          int c;
          
          c = getchar ();
          while (c != EOF) {
                fputc(c);
                c = getchar();
          }
    }
    and got "In fuction 'main' and too few arguments to fuction 'fputc'

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    181
    the syntax for fputc function is
    Code:
    fputc(int, FILE *);
    so your code will be as follow ( and i have made some changes to make your program work fine)

    Code:
    #include <stdio.h>
    
    /* copy input to output; 4st version */
    main()
    {
          FILE *fp;  // need a FIlE pointer to point to the stream
          fp =fopen("c:/output.txt", "r");  // 
          int c;
          
          /*c = getchar ();
          while (c != EOF) {
                fputc(c,stdout);
                c = getchar();
          }*/
          do
          {
              c=fgetc(fp);
              fputc(c,stdout);
          }while(c!=EOF);
          getchar();         
    }
    NOTE: the changes

    - s.s.harish

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Code:
              c=fgetc(fp);
              fputc(c,stdout);
    That's backwards. The OP wants to put keyboard input in a file:
    Code:
      c = getchar();
      fputc(c, fp);
    Another problem is how you changed the loop. Now you're writing EOF to the file since fputc() is coming before the check for exiting the loop.

    Of course, I think this is easier :P
    itsme@itsme:~$ cat > garbage.txt
    this is garbage.
    yay!
    ^Ditsme@itsme:~$ cat garbage.txt
    this is garbage.
    yay!
    itsme@itsme:~$
    Last edited by itsme86; 06-09-2005 at 05:17 PM.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    ok i fixed it thanx 4 all the help but now i wanna take it to another level.....how do i make it take all keystrokes even if they anight in that exe?
    Last edited by ne0x; 06-09-2005 at 11:21 PM.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    bump....i don't know if bumping is allowed but here

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well if you actually formed complete sentences, using real words, you'd be more likely to get an answer.

    how do i make it take all keystrokes even if they anight in that exe?
    Say what now?


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    8
    Alright, When i complie the source and run the .exe a command prompt opens up and what ever i type in the cmd is what is logged in the output.txt. I want to know how to logg all the keystrokes that are typed no matter what window they are in, and send it to the output.txt

  10. #10
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    he wants to know how to make a keylogger
    Hmm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. I'm not THAT good am I?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-19-2006, 10:08 AM
  4. Outputting to a File Modified Text
    By alpha in forum C++ Programming
    Replies: 8
    Last Post: 11-24-2003, 07:39 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

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