Advertisement

12.18.2006 at 11:46AM PST, ID: 22097011
[x]
Attachment Details

How to you find a string in a file in C?

Asked by yankeebushsoftware in C Programming Language

Tags: file, c, string, find

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("BlackHostLog.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
 
Loading Advertisement...
 
[+][-]12.18.2006 at 11:54AM PST, ID: 18161013

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: file, c, string, find
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]12.18.2006 at 01:05PM PST, ID: 18161567

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.18.2006 at 01:12PM PST, ID: 18161625

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:13PM PST, ID: 18161631

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:18PM PST, ID: 18161672

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:19PM PST, ID: 18161678

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:27PM PST, ID: 18161745

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:30PM PST, ID: 18161775

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.18.2006 at 01:32PM PST, ID: 18161785

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:33PM PST, ID: 18161790

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.18.2006 at 01:42PM PST, ID: 18161878

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32