Try this code:<br><br>#include <iostream.h><br>#include <fstream.h><br><br>void main()<br>{<br> char line[81];<br><br> ifstream in_file("your_text_file_path"<br> while (in_file) {<br> in_file.getline(line, 81); <br> // here you put any special processing to line which holds the current line of the text file<br> } <br>}<br><br>This is the easy way using file streams. What is left to do is to make a function to calculate the number of characters.<br>The other way is a bit more difficult:<br><br>#include <stdio.h><br>#include <ctype.h><br><br>int main()<br>{<br> int c;<br> FILE *fp;<br> unsigned int count = 0; // number of characters<br><br> // I miss the if file exist check and error handling stuff<br> fp = fopen("your_file_name", "r" // r - for reading, w - for writing, etc. (see MSDN help)<br> while ((c = fgetc(fp)) != EOF) {<br> count++;<br> }<br> fclose(fp);<br> printf("Characters in file: %d\n", count);<br> return 0;<br>}<br><br>The last example will count all the characters in the file. You can easily fit it to your own needs. Anyway I recommend you use the first method which is C++ specific. Hope this helps! ;-)<br><br>Regards...dex
Dear dex,<br><br>The question was posted in January and marianna has not logged on to tek-tips since February. It is very unlikely that she is still interested in this subject.<br><br>"But, that's just my opinion... I could be wrong".<br>-pete
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.