Solved

Search for the substring in a given string

Posted on 2010-09-16
10
697 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now