By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

comparing string with character

P: n/a
I have made a program in which I'm trying to return the string in
which the character is found.

I'm doing this through pointers. I'm not able to figure out the
correct way:

printf("%s", *string);

while(string != '\0')

{

printf("this is a test");

s = *string;

if(s == w)

{

printf("%c", s);

return (s1);

break;

}

*string++;

Please can some body help me

This is my code : -

#include <stdio.h>

#include <conio.h>

char *xstrchr(char *, char);

void main()

{

char a ='t';

//printf("%c", a);

char b[][8] = {"Scope", "Rule", "Now", "Testing"};

int i;

for(i=0; i<=3; i++)

{

char *p = xstrchr(b[i], a);

//printf("%s", b[i]);

printf("%s", p);

}

/*i=0;

while (b[3][i]!='\0')

{

if (a == b[3][i])

printf("\nThis is a test: %s",
b[i]);

i++;

}*/

}

char *xstrchr(char *string, char w)

{

//while(*string!='\0')

//{

// if (*string == w)

// {

// //printf("%s", string);

// return *string;

// break;

// }

// //printf("%s", string);

// string++;

//}

//char *s1 = string;

printf("%s", *string);

while(string != '\0')

{

printf("this is a test");

if(s == w)

{

printf("%c", s);

return (s1);

break;

}

*string++;

}

printf("\n");

return NULL;

}

Thanks

Pradyut
http://pradyut.tk
http://groups.yahoo.com/group/d_dom/
http://groups-beta.google.com/group/oop_programming
India

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 6 Apr 2005 00:20:46 -0700, Pradyut <pr******@gmail.com> wrote:
I have made a program in which I'm trying to return the string in
which the character is found.


#include<string>
std::string s = "teststring";
s.c_str(); //this returns a char*, a pointer to a zero terminated
sequence of charcters ("C-style string")

to check if a string contains a character, character-sequence, another
string, use the
std::string::find...() methods. a return value != std::string::npos
indicates having found what was searched for.
Jul 23 '05 #2

P: n/a
Eww, C.

char a = 'e';
std::string s("hello");
std::string::iterator found = std::find(s.begin(), s.end(), a);

Now that wasn't so hard, was it?

George Faraj
"Pradyut" <pr******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have made a program in which I'm trying to return the string in
which the character is found.

I'm doing this through pointers. I'm not able to figure out the
correct way:

printf("%s", *string);

while(string != '\0')

{

printf("this is a test");

s = *string;

if(s == w)

{

printf("%c", s);

return (s1);

break;

}

*string++;

Please can some body help me

This is my code : -


Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.