Solved

Search for the substring in a given string

Posted on 2010-09-16
10
718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ finding a sting in a char* string from a text file 3 136
valid enum? 6 81
How and where to get Business Intelligence Development Studio? 2 106
MySQL recovery 7 56
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

738 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