I'm learning C++ and I have hit a road block. I have started to play around with file I/O and I have a program that I want to make.
My Internet is very flakey were I work so I was going to make a program that will tell me when the internet is working and when it's offline.
The plan is to use ping continuously on a target like google and output the results to a file, ping.txt. This is easy to do even for me.
Now, I can read the file and output to the file using c++, but what I want is only the last line of the file. It will say one of the following; host unreachable, timeout, our reply from. Based on this string from the last line of the file I want to create an action such as Internet is ON or Internet is OFF. It also has to run in a loop so that the program updates with each new entry into the file. I think I can do everything except for getting the last line of the ping.txt file into the program.
this syntax is wrong but it gives you an idea of what I want:
thanks for any help,
James
My Internet is very flakey were I work so I was going to make a program that will tell me when the internet is working and when it's offline.
The plan is to use ping continuously on a target like google and output the results to a file, ping.txt. This is easy to do even for me.
Now, I can read the file and output to the file using c++, but what I want is only the last line of the file. It will say one of the following; host unreachable, timeout, our reply from. Based on this string from the last line of the file I want to create an action such as Internet is ON or Internet is OFF. It also has to run in a loop so that the program updates with each new entry into the file. I think I can do everything except for getting the last line of the ping.txt file into the program.
this syntax is wrong but it gives you an idea of what I want:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
char state [56];
char pass [56];
pass[56] =("Reply from ........");
ofstream myfile;
myfile.open ("ping.txt", ios::in);
myfile.gotoEOF
myfile.readTheLastLine >> state [56];
if state[56]=pass[56]
then internet is working
else internet is broke
James
Comment