I have this code in C: How do I code a part to find the string "Sending boot event" that is contained in the BlackHostLog.txt and report a message saying passed to the status file?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//monitor the status of the Black Host Window by its log file and
//update a status text file with a flag value (text) when the status changes.
int main(int argc, char *argv[])
{
char text [100];
//Declare a File Pointer
FILE *file_ptr;
//Open the log file
file_ptr=fopen("BlackHostL
og.txt", "r");
//Test
if(file_ptr != NULL)
{
printf("BlackHostLog.txt opened.\nContents:\n");
//Read the text
while(fgets(text, 100, file_ptr)!=NULL)
{
printf("%s", text);
}
//Create the Status File
file_ptr=fopen("status.txt
","w");
//test
if(file_ptr != NULL)
{
printf("Status File was created\n");
//close the file
fclose(file_ptr);
}
else{printf("Unable to create the status file.\n"); return 1; }
//Close the file
fclose(file_ptr);
system("PAUSE");
return 0;
}
else
{
printf("Unable to open the log file.\n");
return 1;
}
}
Start Free Trial