Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search for the substring in a given string

Posted on 2010-09-16
10
Medium Priority
?
732 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
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.

 

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

596 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