How to test whether strstr() returns a null pointer or not? Do I
use something like the following?
if(NULL != strstr(str1,str 2))
That does not seem to work. 24 12582
John Smith <js****@company .com> wrote:
# How to test whether strstr() returns a null pointer or not? Do I
# use something like the following?
#
# if(NULL != strstr(str1,str 2))
if (strstr(str1,st r2))
always works for me.
#
# That does not seem to work.
#
#
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I'm not even supposed to be here today.
On Sat, 04 Jun 2005 02:56:05 GMT, John Smith <js****@company .com>
wrote: How to test whether strstr() returns a null pointer or not? Do I use something like the following?
if(NULL != strstr(str1,str 2))
That does not seem to work.
Does not work how? Tell us what you expect and what actually
happens. Provide some compilable code that demonstrates this
behavior.
<<Remove the del for email>>
John Smith wrote on 04/06/05 : How to test whether strstr() returns a null pointer or not? Do I use something like the following?
if(NULL != strstr(str1,str 2))
That does not seem to work.
Give a complete example. I suspect that the strings pointed by str1 and
str2 are not the ones you are expecting (say, a extra trailing '\n' for
example...).
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"There are 10 types of people in the world today;
those that understand binary, and those that dont."
On Sat, 04 Jun 2005 04:12:50 +0000, SM Ryan wrote: John Smith <js****@company .com> wrote: # How to test whether strstr() returns a null pointer or not? Do I # use something like the following? # # if(NULL != strstr(str1,str 2))
Yes, that's one way of doing it if (strstr(str1,st r2))
The 2 forms are equivalent so if one doesn't work the other won't either.
Lawrence
"Lawrence Kirby" <lk****@netacti ve.co.uk> wrote # if(NULL != strstr(str1,str 2))
if (strstr(str1,st r2))
The 2 forms are equivalent so if one doesn't work the other won't either.
He might have manged to redefine NULL.
..backwards expressions read to Hard
SM Ryan wrote: John Smith <js****@company .com> wrote: # How to test whether strstr() returns a null pointer or not? Do I # use something like the following? # # if(NULL != strstr(str1,str 2))
if (strstr(str1,st r2))
always works for me.
Thanks. That works.
On Sat, 04 Jun 2005 14:09:19 GMT, John Smith <js****@company .com>
wrote: SM Ryan wrote: John Smith <js****@company .com> wrote: # How to test whether strstr() returns a null pointer or not? Do I # use something like the following? # # if(NULL != strstr(str1,str 2))
if (strstr(str1,st r2))
always works for me.
Thanks. That works.
That's really odd.
if (NULL != strstr(str1, str2))
should be equivalent to
if (strstr(str1, str2))
which should also be equivalent to
if (0 != strstr(str1, str2))
(the use of NULL instead of 0 is a stylistical thing)
What exactly didn't work in your program? I believe the Standard only
requires the macro NULL to be defined in <stddef.h>. Perhaps if you
include <stddef.h> in your program it will work.
On Sat, 04 Jun 2005 16:35:39 +0200, Paul Mesken <us*****@eurone t.nl>
wrote: I believe the Standard only requires the macro NULL to be defined in <stddef.h>.
And <locale.h>, <stdlib.h>, <stdio.h>, <string.h>, <time.h>
Furrfu, that Standard could use a better index :-)
Well, in that case NULL might have been redefined as someone else
suggested, since NULL is defined in <string.h> and you use strstr()
(which, I hope, implies that you also included <string.h>
Barry Schwarz wrote: On Sat, 04 Jun 2005 02:56:05 GMT, John Smith <js****@company .com> wrote:
How to test whether strstr() returns a null pointer or not? Do I use something like the following?
if(NULL != strstr(str1,str 2))
That does not seem to work.
Does not work how? Tell us what you expect and what actually happens. Provide some compilable code that demonstrates this behavior.
Not sure. But if(strstr(str1, str2)) works. So I'll just use that. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Squid Seven |
last post by:
I create a pointer to an item:
CardSession *cardSession;
Then, later, I use new to create an instance of the item and assign it
to that pointer:
cardSession = new CardSession();
In another function, I want to test if an object is assigned to that
|
by: Andrew |
last post by:
Is there anyway to test if a pointer points to allocated memory or
not?
For example if I have a pointer such as char *p is there a standard
way to test whether an assignment such as the following has been
applied?
p = (char *) malloc(sizeof(char) * n);
|
by: Lars Langer |
last post by:
Hi there,
I'm new to this C - never the less - I'm trying to search a string for the
occurence of a substring - However, I'm not very succesful since my use of
the strstr function always returns NULL. But I know that there exsists such
a substring, as I can see it with my own two eye when I print out the string
to be searched. I added the code of the function (resolveResponse)and how I
call this code -
Calling the function:
|
by: OzBob |
last post by:
Am performing the following check to determine if a set of text is at the
start of a string,....
/* Check for literal text DD at beginning of string date_format */
char date_format;
if (strstr(date_format, "DD") != date_format)
{
/* perform swap here */
}
|
by: linq936 |
last post by:
Hi,
I have the following code:
#include <stdio.h>
int main(void){
char* str1 = "abc";
char* str2 = '\0';
if ( strstr(str1, str2) == NULL ){
printf("yes\n");
| |
by: lovecreatesbea... |
last post by:
I'm getting `warning: return discards qualifiers from pointer target
type' at line 11 on this code from gcc.
Some people suggested in old posts that this kind of warning can be
suppressed by qualifying the return type with const. In this code it
also can be removed by removing const from the first pointer parameter
str. Are there better ways to do it, or does it deserve to do this?
/* Search str for sub and return the pointer to the...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |