473,735 Members | 2,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1541
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::fi nd...() methods. a return value != std::string::np os
indicates having found what was searched for.
Jul 23 '05 #2
Eww, C.

char a = 'e';
std::string s("hello");
std::string::it erator found = std::find(s.beg in(), s.end(), a);

Now that wasn't so hard, was it?

George Faraj
"Pradyut" <pr******@gmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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
6082
by: vertigo | last post by:
Hello How can i check if $mystring is exactly equal to "." Where "." means one character (comma) ? Thanx Michal
11
461
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
4
10535
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 sets of character strings from the user. Then I want to run through each element and compare the two strings. If they match I print they match... I'm having a bit of trouble with the actual loop through each array using the pointers and comparing...
41
3953
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 Y contains all the elements that are B but not in A. Z will then have the elements that are in both A and B. One way of doing this is of course to iterate throug the lists and compare each of the element, but is there a more efficient way? ...
6
3571
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 gives me a core dump. char *point; point = str; while (point != '\0') { if (isalpha(point)) // It does not work either: if
88
22045
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 wondering if one is better than the other or if there is some sort of hybrid of the two that would be superior. IMPLEMENTATION 1: #ifndef HAVE_STRCASECMP
0
2394
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 D 'Delete
10
11314
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
4671
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 found was to use Reflection to access the private _ignoreCase field, which I'd rather not do. It seems to me that a public readonly property would be helpful. (Better yet, it should probably have a CompareOptions) 2) The CompareInfo.Compare method...
0
9460
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6045
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3269
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2186
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.