errakeshpillai
Full Member level 5
- Joined
- Oct 17, 2011
- Messages
- 255
- Helped
- 64
- Reputation
- 128
- Reaction score
- 59
- Trophy points
- 1,328
- Location
- Chennai, India
- Activity points
- 2,738
#include<stdio.h>
char *xstrchr(char *,char );
void main()
{
char a[50];
char b;
printf("\n enter the string:");
scanf("%s",a);
b=getchar();
char *c;
c=xstrchr(a,b);
if(c!=NULL)
{
printf("\n the character found!!!!");
}
else
printf("\n the character not found!!!");
}
char *xstrchr(char *a, char b)
{
char *c;
while(*a)
{
if(b==*a)
{
c=a;
return c;
}
a++;
}
return NULL;
}
enter the string:sathish
the character not found!!!
the output i got is mentioned above...
#include<stdio.h>
char *xstrchr(char *,char );
void main()
{
char a[50];
char b;
printf("\n enter the string:");
b=getchar();
scanf("%s",a);
char *c;
c=xstrchr(a,b);
if(c!=NULL)
{
printf("\n the character found!!!!");
}
else
printf("\n the character not found!!!");
}
char *xstrchr(char *a, char b)
{
char *c;
while(*a)
{
if(b==*a)
{
c=a;
return c;
}
a++;
}
return NULL;
}
hi mathes,the code working when defined the b=getchar(),above the string input values of a ,whats the reason??
#include<stdio.h>
#include<string.h>
char *xstr(char *,char *);
int main()
{
char a[50],b[50];
char *c;
printf("\n enter the string:");
fgets(a,50,stdin);
printf("\n enter the substring:");
scanf("%s",b);
c=xstr(a,b);
if(c!=NULL)
printf("\n substring present!!!!");
else
printf("\n the substring not present!!!!");
}
char *xstr(char *x,char *y)
{
char *z,*a;
char b[20][50];
a=x;
int i,j;
i=j=0;
while(*a)
{
if(*a==' ')
{
a++;
b[i++][j]='\0';
j=0;
continue;
}
b[i][j++]=*a;
a++;
}
b[i][j]='\0';
int m,cn;
cn=i;
printf("\n");
for(m=0;m<=cn;m++)
printf("%s\n",b[m]);
for(m=0;m<=cn;m++)
{
if(strcmp(b[m],y)==0)
{
z=b[m];
return z;
}
}
return NULL;
}
enter the string:s
enter the substring:s
s
the substring not present!!!!
#include<stdio.h>
#include<string.h>
char *xstr(char *,char *);
int main()
{
char a[50],b[50];
char *c;
printf("\n enter the string:");
fgets(a,50,stdin);
printf("\n enter the substring:");
scanf("%s",b);
c=xstr(a,b);
if(c!=NULL)
printf("\n substring present!!!!");
else
printf("\n the substring not present!!!!");
}
char *xstr(char *x,char *y)
{
char *z,*a;
char b[20][50];
a=x;
int i,j;
i=j=0;
while(*a)
{
if(*a==' ' || *a =='\n')
{
a++;
b[i++][j]='\0';
j=0;
continue;
}
b[i][j++]=*a;
a++;
}
b[i][j]='\0';
int m,cn;
cn=i;
printf("\n");
//for(m=0;m<=cn;m++)
//printf("%s\n",b[m]);
for(m=0;m<=cn;m++)
{
if(strcmp(b[m],y)==0)
{
z=b[m];
return z;
}
}
return NULL;
}
printf("\n enter the string:");
fgets(a,50,stdin);
printf("\n enter the substring:");
scanf("%s",b);
while(*a)
{
if(*a==' ')
{
a++;
b[i++][j]='\0';
j=0;
continue;
}
b[i][j++]=*a;
a++;
}
b[i][j]='\0';
whats the solution for this??
#include <stdio.h>
int main()
{
char a[20],b[20];
int i=0,j=0;
printf("\nEnter a string:");
fgets(a,20,stdin);
while(b[j++]=a[i++]);
printf("\nCopied string is %s\n",b);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?