473,856 Members | 1,750 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 1548
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
6085
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
10546
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
3979
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
3577
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
22129
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
2400
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
11352
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
4677
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
9904
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10773
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
9527
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...
1
7929
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7087
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
5756
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...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4170
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.