• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 22 رای - 2.5 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: نحوه عملکرد توابع strchr و strrchr
حالت موضوعی
#1
کد:
#include <iostream>
#include <string>
using namespace std;
void main(void)
{
   char ch='r';
   char string[] =
"The quick brown dog jumps over the lazy fox";
   char fmt1[] =
"         1         2         3         4         5";
   char fmt2[] =
"12345678901234567890123456789012345678901234567890";
   char* pdest;
   int result;
   cout<<"String to be searched: \n\t\t"<<string<<"\n";
    cout<<"\t\t"<<fmt1<<"\n\t\t"<<fmt2<<"\n\n";
    cout<<"Search char:\t"<<ch<<"\n";
/* Search forward. */
   pdest=strchr(string, ch);
    result=pdest - string + 1;
    if( pdest != NULL )
       cout<<"Result:\tfirst "<<ch
           <<" found at position "<<result<<"\n\n";
    else
       cout<<"Result:\t"<<ch<<" not found\n";
/* Search backward. */
   pdest=strrchr(string, ch);
    result=pdest - string + 1;
    if( pdest != NULL )
       cout<<"Result:\tfirst "<<ch
           <<" found at position "<<result<<"\n\n";
    else
       cout<<"Result:\t"<<ch<<" not found\n";
}

//end
 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  توابع جستجوی یک زیر رشته در رشته هایی از نوع string Ghoghnus 0 2,906 05-24-2012، 10:12 PM
آخرین ارسال: Ghoghnus

پرش به انجمن:


Browsing: 1 مهمان