473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

comparing string with character

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
2 1521
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: vertigo | last post by:
Hello How can i check if $mystring is exactly equal to "." Where "." means one character (comma) ? Thanx Michal
11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
6
by: Erwin | last post by:
Suppose I have a string, char *str = "1 2 a f g < )" and I need to check each of the components in the loop using isalpha, isdigit, isspace. How can I do that? I tried to do using this code, but...
88
by: William Krick | last post by:
I'm currently evaluating two implementations of a case insensitive string comparison function to replace the non-ANSI stricmp(). Both of the implementations below seem to work fine but I'm...
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
5
by: =?Utf-8?B?UElFQkFMRA==?= | last post by:
Not really a C#-specific comment, more general .net observations. 1) A while back I found the need to determine whether or not a particular StringComparer was case-insensitive. The best way I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.