LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2003, 05:10 PM   #16
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111

strcmp() only returns 0 when the two strings are exactly the same.
Use strstr() for your purpose.
Or do I understand your purpose wrong? Is searching for a substring in the output not what you want to do?
 
Old 10-13-2003, 05:17 PM   #17
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
umm no, u got me right.
ok again - im passing a string to this function, and i want to check if that string is in the output of the system cmd we just executed.
now, i know what that string im passing is, so, i make another string with {char *temp = "mystring";}, and if i use it in the code block u wrote (and frankly, in all that we started off with), it works fine.

now since i know that temp is supposed to be whats passed to this function, i use strcmp() to check if thats what is being passed to it by comparing it to the string i pass to the function. and sure enough, it doesnt return a 0, and the code block fails. although when i print them both out, they "look" the same.

thats whats bothering me.

could it have to do with a terminating character or something?
 
Old 10-13-2003, 06:26 PM   #18
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
ok, got it. the problem was i needed some coffee, and now its working.
the string being passed had an empty char at the start, which is why strcmp() and strlen() were giving me no matches, even though both variables output the same string.


thanks a million billion , esp Hko.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
search for a string in c alaios Programming 1 07-07-2005 04:50 PM
C....Search a string for a string Scrag Programming 4 06-14-2004 04:15 PM
[c++] Search in a string hylke Programming 5 06-14-2004 11:20 AM
search for my string alaios Linux - General 6 05-08-2004 01:32 PM
Search for a string TheOriginalH Linux - General 5 09-24-2003 10:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration