PDA

View Full Version : جستجوی یک رشته درون رشته دیگر



pooria_googooli
یک شنبه 20 دی 1388, 21:21 عصر
دوستان اگه میشه بگید چجوری میتونم یه رشترو تو یه رشته دیگه جستجو کنم.

hmrbesharat
یک شنبه 20 دی 1388, 22:54 عصر
میتونی از تابع


strstr(st1,st2);
استفاده کنی

Salar Ashgi
یک شنبه 20 دی 1388, 23:07 عصر
توضیح کاملتر :



#include <iostream>
#include <conio>
#include <string>
int main(){
typedef char string[100];
string a,b;
cin>>a>>b;
cout<<strstr(a,b)<<endl;
getch();
}

pooria_googooli
یک شنبه 20 دی 1388, 23:33 عصر
ازین تابع استفاده کردم. ولی نشد. آخه مشکل من اینه که دو تا رشته هام آرایه هستن. و رشته ای که باید توش جستجو انجام بشه دو بعدیه

hmrbesharat
یک شنبه 20 دی 1388, 23:48 عصر
کدتا بزا تا برسیش کنیم

Salar Ashgi
دوشنبه 21 دی 1388, 00:06 صبح
ازین تابع استفاده کردم. ولی نشد. آخه مشکل من اینه که دو تا رشته هام آرایه هستن. و رشته ای که باید توش جستجو انجام بشه دو بعدیه

کاری که میخواهید انجام دهید را بطور دقیق بیان کنید .

pooria_googooli
دوشنبه 21 دی 1388, 12:15 عصر
ببینید من دارم برنامه دفترچه تلفن مینویسم. و از بانک اطلاعاتیم استفاده نمیکنم. یعنی با بسته شدن برنامه اطلاعات پاک میشه. منظورم همون استفاده از آرایه هاست. قسمت سرچ این برنامم میخوام جوری باشه که یه تیکه از آدرس رو که میدی تمام مشخصات طرف رو بهت بده.

pooria_googooli
دوشنبه 21 دی 1388, 12:30 عصر
در ضمن من با ++dev c مینویسم

hmrbesharat
دوشنبه 21 دی 1388, 23:01 عصر
دوست عزیز تو اون تیکه برنامتا بزار تا کامل جوابتا بدم

pooria_googooli
سه شنبه 22 دی 1388, 09:22 صبح
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
void enter(int[],char[],char[],int i);
int main()
{
int a;
int i=1;
int tel[10];
char search[90];
char help[1][90];
char name[10][90];
char family[10][90];
char addres[10][90];
Lable:
cout<<"1-Add new number\n2-Search\n3-Exit\n";
cout<<"Enter a number you want\n";
scanf("%d",&a);
switch(a)
{
case 1 :
cout<<"\n Enter the name: ";
scanf("%s", name[i]);
cout<<"\n Enter the family: ";
scanf("%s", family[i]);
cout<<"\n Enter the tel number: ";
scanf("%d", &tel[i]);
cout<<"\n Enter the enter the addres: ";
scanf("%s", addres[i]);
i++;
system("cls");
goto Lable;
case 2:
cout<<"enter the addres";
scanf("%s",search);
int pos;
for(int j=1;j<=10;j++)
{
string s1 =address[i][];
string s2 =search[];
int pos;
pos = strstr(s1,s2);
if(pos!=-1)
{
int h=i;
break
}

}
cout<<tel[h]<<name[h][]<<family[h][]<<address[h][];

}
getch();
return 0;
}

hmrbesharat
سه شنبه 22 دی 1388, 22:59 عصر
گفتم کدتا بده برات حل میکنم بیا انم کدت

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
void enter(int[],char[],char[],int i);
int main()
{clrscr();
int a,h;
int i=1;
int tel[10];
char search[90];
char help[1][90];
char name[10][90];
char family[10][90];
char address[10][90];
Lable:
cout<<"1-Add new number\n2-Search\n3-Exit\n";
cout<<"Enter a number you want\n";
scanf("%d",&a);
switch(a)
{
case 1 :
cout<<"\n Enter the name: ";
scanf("%s", name[i]);
cout<<"\n Enter the family: ";
scanf("%s", family[i]);
cout<<"\n Enter the tel number: ";
scanf("%d", &tel[i]);
cout<<"\n Enter the enter the addres: ";
scanf("%s", address[i]);
i++;
//system("cls");
clrscr();
goto Lable;
case 2:
cout<<"enter the address :";
scanf("%s",search);
char *pos;char s1[90],s2[90];
for(int j=1;j<=10;j++)
{
//string s1 =address[i][];
//string s2 =search[];
strcpy(s1,address[j]);
strcpy(s2,search);
pos = strstr(s1,s2);
if(pos!=NULL)
{
h=j;
break;
}

}
cout<<tel[h]<<"\n"<<name[h]<<"\n"<<family[h]<<"\n"<<address[h];

}
getch();
return 0;
}
اگه جایی مشکل داشتی بگو حل کنم

pooria_googooli
سه شنبه 22 دی 1388, 23:58 عصر
مشکل دیگه ای که دارم برا تابع delay و Sleep هست. با اینکه هدر هاش رو میذارم بازم ارور میده.

hmrbesharat
پنج شنبه 24 دی 1388, 17:27 عصر
قبلا هم گفته بودم كدتا بزار تا برات مشكلشا پيدا كنيم
اون پايين يه كليد تشكر هست ديدي!!!! جديدا گذاشتن:چشمک:

reza_akbari2009
یک شنبه 23 آبان 1389, 12:12 عصر
دوستان میشه به جای استفاده از کد:
strstr(st1,st2);


از توابع بازگشتی استفاده کرد ؟چطوری؟

هم دانشگاهی
سه شنبه 25 آبان 1389, 21:16 عصر
ببین من قبلا یه کد نوشتم که یه رشته رو تو رشته دیگه پیدا میکرد!

ببین بدرت میخوره! :لبخندساده: