A
Ajay
Hi all,Could anybody tell me the most efficient method to find a substr
in a string.
in a string.
Ajay said:Hi all,Could anybody tell me the most efficient method to find a substr
in a string.
Ajay said:Hi all,Could anybody tell me the most efficient method to find a substr
in a string.
Ajay said:Hi all,Could anybody tell me the most efficient method to find a substr
in a string.
somu said:hi ajay
take the two string in the form of array
compare the second with the first
through loop
match both
nu will get the matching string
that can b later taken out
somu said:hi ajay
take the two string in the form of array
compare the second with the first
through loop
match both
nu will get the matching string
that can b later taken out
Ajay said:Hi all,Could anybody tell me the most efficient method to find a substr
in a string.
Ajay said:Hi all,Could anybody tell me the most efficient method to find a substr
in a string.
<snipped awful code>May this code help U.............
************************************
May this code help U.............
No such header in standard C.#include<conio.h>
Illegal return type for main.void main()
No such function in standard C.clrscr();
Declarations after executable statement, illegal according the C89char s1[50],s2[20];
> int i,j,f=0;
A prompt without a '\n' or a following fflush(stdout). There is noprintf("Enter main string : ");
One of the worst errors that can be made in a C program. Never usegets(s1);
Given Code can help U................
#include<stdio.h>
#include<conio.h>
#include<string.h>
int substring(char *,char *);
void main()
{
clrscr();
char s1[50],s2[20];
int i,j,f=0;
printf("Enter main string : ");
gets(s1);
printf("Enter substring to be searched in main string : ");
gets(s2);
if(substring(s1,s2)!=0)
printf("\nFound");
else
printf("\nNot found");
getch();
}
int substring(char *s1,char *s2)
{
int f=0;
for(;*s1!='\0'
{
if(*s2=='\0')
break;
for(;*s2!='\0'
{
if(*s1==*s2)
{
f=1;
s1++;
s2++;
}
else
{
f=0;
s1++;
break;
}
}
}
if(f==0)
return 0;
else
return 1;
getch();
}
May this code help U.............
************************************
#include<stdio.h>
#include said:#include<conio.h>
#include<string.h>
int substring(char *,char *);
void main()
{
clrscr();
char s1[50],s2[20];
int i,j,f=0;
printf("Enter main string : ");
gets(s1);
printf("Enter substring to be searched in main string : ");
gets(s2);
if(substring(s1,s2)!=0)
printf("\nFound");
else
printf("\nNot found");
getch();
}
int substring(char *s1,char *s2)
{
int f=0;
for(;*s1!='\0'
{
if(*s2=='\0')
break;
for(;*s2!='\0'
{
if(*s1==*s2)
{
f=1;
s1++;
s2++;
}
else
{
f=0;
s1++;
break;
}
}
}
if(f==0)
return 0;
else
return 1;
getch();
Martin Ambuhl said:[etc. ...]May this code help U.............
So, tell us: are you a troll or just a very, very bad programmer?
Count the quote marks.Martin Ambuhl said:[etc. ...]May this code help U.............
So, tell us: are you a troll or just a very, very bad programmer?
You help the guy but then insult him?
Al Balmer said:Count the quote marks.Martin Ambuhl said:(e-mail address removed) wrote:
May this code help U.............
[etc. ...]
So, tell us: are you a troll or just a very, very bad programmer?
You help the guy but then insult him?
By eye.
Ajay said:Hi all,Could anybody tell me the most efficient method to find
a substr in a string.
Given Code can help U................
****************************************************************
#include<stdio.h>
#include<conio.h>
#include<string.h>
int substring(char *,char *);
void main()
{
clrscr();
char s1[50],s2[20];
int i,j,f=0;
printf("Enter main string : ");
gets(s1);
printf("Enter substring to be searched in main string : ");
gets(s2);
if(substring(s1,s2)!=0)
printf("\nFound");
else
printf("\nNot found");
getch();
}
int substring(char *s1,char *s2)
{
int f=0;
for(;*s1!='\0'
{
if(*s2=='\0')
break;
for(;*s2!='\0'
{
if(*s1==*s2)
{
f=1;
s1++;
s2++;
}
else
{
f=0;
s1++;
break;
}
}
}
if(f==0)
return 0;
else
return 1;
getch();
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.