Question : find a word in an external .txt and get into my VC++ code?

Hello
I have a code that reads a word in an external .txt and stores it in a variable.

Now, i need to change this code so i could retrieve the XXXXxX  word in the only and the first line of the external file that looks like this:

 
1:
INDEX (S): [/opt/fox/env/XXXxX.env]


One more thing. The content of this external files changes the INDEX content and the XXXXxX. The rest is constant

How can i do it??

Kind regards!

This is the code:
 
1:
2:
3:
4:
5:
6:
7:
FILE * pFile;
   char env [100];
   pFile = fopen ("C:\\myfile.txt" , "r");
  
   fgets (env , 100 , pFile);
   fclose (pFile);
   if(strstr(env, "To_Match_This") != (char*) &env[0])

Answer : find a word in an external .txt and get into my VC++ code?

this should help
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
   pFile = fopen ("C:\\myfile.txt" , "r");
  
   fgets (env , 100 , pFile);
   fclose (pFile);

   // fetch XXXXXXX
   const char * lastSlash = strrchr(env, '//');
   if(lastSlash != NULL) 
   {
      const char* lastPeriod = strchr(lastSlash, '.');
      if(lastPeriod != NULL) 
      {
         // Better to copy to some other var, for ex. overwriting env
         strncpy(env, lastSlash + 1, lastPeriod - lastSlash - 1);
      }
   }
Random Solutions  
 
programming4us programming4us