Reading from the keyboard


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Reading from the keyboard

  1. #1
    Jason Guest

    Reading from the keyboard


    I am trying to write a program that reads text from tyhe keyboard and writes
    it to disk but it doesn't seem to be working, i would appreaicate any help.
    Thank you for your time.


    #include <stdio.h>
    #include <stdlib.h>


    FILE *thefile;
    char ch;

    int main(void)
    {
    thefile = fopen("word","w");

    while(ch! = EOF)
    {
    ch = getch();
    putc(ch);
    fputc(ch, thefile);
    }
    fclose(thefile);
    return 0;
    }

  2. #2
    Mike Guest

    Re: Reading from the keyboard


    Hi Jason the problem is in your while loop. Since ch never = EOF the loop
    never terminates. You will have to find another way to terminate the loop.
    Or another way to limit or control user input.

    Mike

    "Jason" <BA3NZ@chocolatecentral.net> wrote:
    >
    >I am trying to write a program that reads text from tyhe keyboard and writes
    >it to disk but it doesn't seem to be working, i would appreaicate any help.
    >Thank you for your time.
    >
    >
    >#include <stdio.h>
    >#include <stdlib.h>
    >
    >
    >FILE *thefile;
    >char ch;
    >
    >int main(void)
    >{
    > thefile = fopen("word","w");
    >
    > while(ch! = EOF)
    > {
    > ch = getch();
    > putc(ch);
    > fputc(ch, thefile);
    > }
    > fclose(thefile);
    > return 0;
    >}



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center