Results 1 to 3 of 3

Thread: Well then, how about reading a character at a time

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    If anyone has C++ code that reads an input string one character at a time, I would appreciate it if you would post it.

    I would like to see if I can read in a file and strip out the carriage returns from it.

    Thank you.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Hmm I did have something like that that I wrote a while ago, but I think I've formatted my hard disk since then. Ah well, here's the jist of it:

    Code:
    char *path = "c:\\yourpath\\yourfile.txt";
    FILE *fp = fopen(path, "r");  // "r" means open for reading
          //you should check for a NULL pointer here, which 
          //means the fopen() failed
    
    char currentChar;
    
    while(!feof(fp))       //while not end-of-file
    {  currentChar = fgetc(fp);
       //do something with your character here
    };
    
    fclose(fp);  //close your file once you're finished
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Thanks a lot !

    I will give your code here and your suggestion in the other thread a try.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width