Solved

Search for the substring in a given string

Posted on 2010-09-16
10
706 Views
Last Modified: 2013-11-17
Hi folks,

            How to search for the substring in a given string with case insensitive in c++ .?  
0
Comment
Question by:Ananth304
  • 6
  • 4
10 Comments
 
LVL 32

Expert Comment

by:phoffric
ID: 33689362
Here is a similar problem:    http://www.cplusplus.com/forum/beginner/19970/
0
 
LVL 32

Expert Comment

by:phoffric
ID: 33689390
0
 
LVL 32

Expert Comment

by:phoffric
ID: 33689393
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

Author Comment

by:Ananth304
ID: 33689412
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
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 33689436
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
 

Author Comment

by:Ananth304
ID: 33690106
Hi phoffric,


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

                 
0
 
LVL 32

Expert Comment

by:phoffric
ID: 33690960
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
 

Author Comment

by:Ananth304
ID: 33691027
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
 
LVL 32

Expert Comment

by:phoffric
ID: 33691359
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
 

Author Comment

by:Ananth304
ID: 33700238
HI phoffric,

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

       Take care,
       Ananth
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Automate Upload with Git using Bit Bucket / Source Tree 4 74
eclipse luna javeEE perspecive missing 5 110
NOTEPAD++ Meaning of (+) and (-) Icons 6 125
Copying WordPress Pages 5 83
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question