Click to See Complete Forum and Search --> : Well then, how about reading a character at a time
jbart
Dec 7th, 2000, 09:33 AM
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.
HarryW
Dec 7th, 2000, 11:57 AM
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:
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
jbart
Dec 7th, 2000, 01:45 PM
Thanks a lot !
I will give your code here and your suggestion in the other thread a try.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.