• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 733
  • Last Modified:

Search for the substring in a given string

Hi folks,

            How to search for the substring in a given string with case insensitive in c++ .?  
0
Ananth304
Asked:
Ananth304
  • 6
  • 4
1 Solution
 
phoffricCommented:
Here is a similar problem:    http://www.cplusplus.com/forum/beginner/19970/
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Ananth304Author Commented:
Hi phoffric,
 
            I have to go to further step after doing this. So I  have to make condition for this. how to do it..?
0
 
phoffricCommented:
I think there is a common theme in these links. First you have to normalize the pattern and the search string by making them both either upper or lower case. Then perform the normal search using one of the techniques in the links (depending upon which environment you are in).

If you have a particular question about the link, please ask. I'll be leaving shortly until tomorrow, but others should be able to answer them.
0
 
Ananth304Author Commented:
Hi phoffric,


             Thank you so much for the help.. Its working fine... Thanks once again....

                 
0
 
phoffricCommented:
You're very welcome. Glad to hear it is working fine. Hope you learned much. If you would like to post your code for review, I'd be happy to take a look at it tonight.
0
 
Ananth304Author Commented:
Hi  phoffic,

                   Yes sure.. I have attached the code...
//---------------------------------------------------------------------------

#include <vcl.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <fstream>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>

#include <winspool.h>

using namespace std;//*************

#pragma hdrstop

#include "test.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


DOC_INFO_1 GlobalDocInfo;
int delSpooler()
{
 DWORD dwBufsize=0;
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
int count;
 OpenPrinter("Canon MF4320-4350", &hPrinter, NULL);
 DWORD bytesNeeded =0, jobsReturned=0;
  GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize);

    PRINTER_INFO_2* pinfo = (PRINTER_INFO_2*)malloc(dwBufsize);
    long result = GetPrinter(hPrinter, 2,(LPBYTE)pinfo, dwBufsize, &dwBufsize);
    DWORD numJobs = pinfo->cJobs;
    free(pinfo);//free now


    if ( numJobs == 0)
    {
        //cout << "No printer jobs found." << endl;
        ShowMessage("No printer jobs found.");
    }

    else //Some Jobs in queue
    {

        JOB_INFO_1 *pJobInfo=0;
        DWORD bytesNeeded =0, jobsReturned=0;

       // Get info about jobs in queue.
        EnumJobs(hPrinter, 0, numJobs, 1, (LPBYTE)pJobInfo, 0,&bytesNeeded,&jobsReturned);
        pJobInfo = (JOB_INFO_1*) malloc(bytesNeeded);
        EnumJobs(hPrinter, 0, numJobs, 1, (LPBYTE)pJobInfo, bytesNeeded,&bytesNeeded,&jobsReturned);
        string str = "POLYTECH";
        /*string str1 =*/
        //string firch = str.substr(0,2);
        char *pch;
       // char *pc;
       // char pch1;
        //char *pch2;

        //Loop and delete each waiting job
        for(count =0; count < jobsReturned; count ++)
        {


           //cout << "Deleting JobID  " << pJobInfo[count].JobId;
            //pch = strstr(pJobInfo[count].pDocument, "Polytech");

           // pch1 = toLower(pch);
           // pch2 = toUpper(str);
           //  pch = strstr(pJobInfo[count].pDocument, pch1);
           //  pc = strstr(pJobInfo[count].pDocument, pch2);

              //if(pJobInfo[count].pDocument == GlobalDocInfo.pDocName)
              strlwr(pJobInfo[count].pDocument);
               pch = strstr(pJobInfo[count].pDocument, "polytech"); 
            if(pJobInfo[count].pDocument == pch)
            {
            if ( SetJob(hPrinter, pJobInfo[count].JobId,0,NULL, JOB_CONTROL_DELETE) !=0)
            {
                //cout << "...... Deleted OK" << endl;
                ShowMessage("...... Deleted OK");
            }
           else
            {
                //cout << "...... Failed to Delete" << endl;
                ShowMessage(".........Failed to Delete");
            }
         }
     
  }

        free(pJobInfo);//free now

    }
ClosePrinter( hPrinter );


    return 0;

}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  delSpooler();
}
//---------------------------------------------------------------------------

Open in new window

0
 
phoffricCommented:
Hi Ananth304,

  Well, I see that you are using a dialect that I'm not familiar with. Functions like strlwr are not part of the ANSI standard, which is what I deal with. Of course, if you have any desire to have someone review your code, you can post this in a question with zones including MS and C++.

  You may wish to consider this point, since the code may be less portable if ever moving to another OS or compiler. I've been on projects where we migrate from VxWorks to Red Hat Linux, so it was fortunate that we stuck with ANSI wherever possible.

  Best Regards,
     Paul
0
 
Ananth304Author Commented:
HI phoffric,

       Well its not your fortunate,but its my luck that I get people like you. :)

       Take care,
       Ananth
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now