removing blank lines from a file

i read in a text file and saved it as "file"

i now want to remove all the blank lines from "file".
number of lines in file
Replace all asterisks ('*') with the string "STAR".
Print the number of lines removed from the file
Print the number of numeric digits (0..9).
above all in a loop

so far i have the following
/* reading in all information from input text file
using the .eof method and saving it to "file" for later use*/
if(input.eod()){
string input_string;
while(!input.eof()){
file = getline(input, input_string);
cout<< file << endl;
}
}

/* removing all blank lines from "file"
and saving this into file2*/ // i am lost at how to do the loop
for the remainder of the problem




Last edited on
First check if a string is blank or not (get one line into a string using getline()).
Then , if it is empty, increase a counter to keep total blank line by one.
Else, use a for loop to go through each character, and when you find a *, break the string and add STAR there. and then add the remaining part.

Include the <cctype> header file. Use the isdigit() function to see if a character is a number, if it is, increase another counter for number of digits by one.

Reference:

cctype: http://www.cplusplus.com/reference/clibrary/cctype/
string:
http://www.cplusplus.com/reference/string/
Topic archived. No new replies allowed.