C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2013, 09:39 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Exclamation Help in strcmp

i tried to use strcmp in comparing a data but im not satisfied for the result it is posible to use strcmp to compare multiple data ? can you please help me to solve my problem ... please

here is my code in strcmp
char data1[10],data[10];
data1[0] = NULL;
if (strcmp(data1, data2) != 0){
}


Reply With Quote
  #2  
Old January 4th, 2013, 10:47 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
Each call to strcmp compares two strings. That is what it does. What else are you wanting it to do?

Your sample code does not make much sense:
Code:
    char data1[10],data[10];
    data1[0] = NULL; 
    if (strcmp(data1, data2) != 0)
    {
    }

You don't use data and you don't declare data2, so I guess that the declaration was a typo.

NULL is a pointer, not a char. The char, according to Campbell's book on serial communication, would be NUL, with one "L", but to my knowledge NUL means nothing in a C program. Rather, what you want to use is the char literal, '\0'.

If you need to review the difference between a char and a pointer, then ask.

And you still need to explain just what it is that you're wanting to do.

Reply With Quote
  #3  
Old January 4th, 2013, 11:58 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
And you still need to explain just what it is that you're wanting to do.[/QUOTE]

actually this is the data source and i want to compare according to fruit, veggies, and drinks, etc.

the data source is not in order like this ...

001 fruit apple
002 fruit mango
003 vegetable carrots
004 vegetable radish
005 drinks water
006 fruit water melon
999 fruit melon


please help me ....

Reply With Quote
  #4  
Old January 5th, 2013, 12:27 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
Compare what to what?

Each comparison between two strings is a separate call to strcmp. If you need to make multiple comparisons, that will call for multiple calls to strcmp.

Your problem is not with strcmp itself, but rather with the overall program and algorithm (how you are going to make all those comparisons and then make them give you the results you want). What we are lacking is that overall algorithm.

Reply With Quote
  #5  
Old January 5th, 2013, 02:20 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
i want to compare the set of description like fruit, vegetables, and drinks and i will form it like this

fruit // main head
001 apple
002 mango
006 water melon
999 melon // etc

vegetables // main head
003 carrots
004 radish
//etc

drinks // main head
005 water
501 softdrinks //etc

the number before the apple and etc will be the sequence of data ...

this will be the output it is posible to use strcmp in multiple data the source will get in a flatfile ... thanks

Reply With Quote
  #6  
Old January 5th, 2013, 02:55 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
Huh?

In my first civilian job, I was ahead of everybody else because I was the only one with a degree in computer science and I had two years experience with Pascal going in (at that time, aerospace was gearing up for Ada, for which there was not yet any certified compiler, so everybody was using Pascal which was a stepping stone to Ada; one book was divided into two parts: Part One, how incredibly like Pascal Ada is, and Part Two, how incredibly unlike Pascal Ada is.

In my second civilian job, I was completely behind everybody else. Every week, we had to map our progress according to our planned progress. The problem I had was that we "code pigs" naturally think in terms of writing code. However, the secret to software development is to do most of your work in designing the software, after which the coding phase is very short and uneventful. A "code pig" immediately starts to write code, even though he has no idea what that code is supposed to do. Obviously, the "code pig's" approach wastes a lot of time and effort.

Screw the actual code! What is your design? Before you write even one single line of code, what exactly is it that you are trying to do? And how exactly do you intend to do it? Once you are able to state that, then anybody would be able to code it.

Most of the work in software development is in the design! The rest could be done by a trained monkey!

So then, what is your design?

Reply With Quote
  #7  
Old January 5th, 2013, 03:26 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
sir i dont encounter the pascal programming even C language
i dont have any idea about this language but
i want to learn from it so i want to ask and help me
if the "strcmp" is posible to use to compare multiple data like what i ask in this thread ... and how can i do

sorry for misunderstand ......

Reply With Quote
  #8  
Old January 5th, 2013, 04:14 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
WTF????

Design!!!!!!!!!!

Just what the **** are you trying to do????????????

Decide just what exactly it is that you want to do and how to do it!!!!!!!!

Once you have decided that, then coding it is ridiculously simple.

So just what exactly are you trying to do? Your message #5 makes absolutely no sense to me. Until you can precisely define just what exactly you want to do, there is nobody on this entire planet who could possibly produce the code that you need. But once you precisely define just what exactly you want, then the implementation will be trivial.

So it is entirely up to you to precisely define what comparisons you want to be performed.

We are still waiting.

Reply With Quote
  #9  
Old January 5th, 2013, 06:37 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,905 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 9 m 41 sec
Reputation Power: 1774
Seems like a lost cause to me.
http://forums.devshed.com/c-program...ing-936992.html
OP persistently goes out of their way to make it really hard to offer any help at all.

I'm far from convinced that they learnt a damn thing in the last 6 months as the first thread is pretty much the same as this thread.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #10  
Old January 5th, 2013, 07:18 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,824 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 21 h 1 m
Reputation Power: 1800
In C a string is an array of characters with a '\0' character indicating the end of the useful data. The strcmp() function compare one string with another.

In your example, the strings being compared were not initialised to anything remotely useful. You would do better to copy and paste your actual code since your example does nothing to classify your intent.

Given your data list, you will need to write code that reads that data and tokenises it into individual strings that can them be compared.

It is entirely unclear what you mean by "compare multiple data". As I said strcmp() compares exactly one string with exactly one other. It is not a sort function.

If you need to process data of any kind (especially in a proprietary format) there is unlikely to be a single existing standard function that will magically do it for you, you do actually have to program it! The standard library is a set if building blocks not a set of canned solutions.

The point is there is a huge gap between what you are asking (very low level operation) and what you appear to be attempting to do (very high level operation). Perhaps what you should do is ask a question about what you want to achieve. Such as for example:
Quote:
"Given the data below in a file data.dat, how could I generate a file sorted_data.dat with the data sorted numerically using the first space delimited field as the sort order key?"


You could ask a question like that on whatever it is you want to do, and it would be clear and unambiguous, however this is not a free programming service, it is a forum for those interested in programming and learning, so you would need to show some effort to start with - some credible attempt at a solution. You might then get help with specific areas of difficulty or confusion; you are unlikely to get a complete solution.

The answer as it happens would involve file handling, string handling, and sorting - all of which are supported by the standard library, but you are perhaps being too specific by asking only about strcmp() and expecting it to be capable of solving your entire problem. Programming does not work like that!

Last edited by clifford : January 7th, 2013 at 04:34 AM.

Reply With Quote
  #11  
Old January 7th, 2013, 03:09 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by clifford
As I said strcmp() compares exactly one string with exactly one other. It is not a sort function.


thank sir this could be the answer that i want to know ....
my program that i create is for transaction and reports and compare any transaction according to details heres my code sir
http://forums.devshed.com/c-program...ing-936992.html
by the way thanks for the help sir ... sorry if i dont understand the other deep words in proframming ..

Quote:
Originally Posted by salem

http://forums.devshed.com/c-program...ing-936992.html


yes sir its same problem coming from me .. thats all my coding the others are usefull to input ...

Reply With Quote
  #12  
Old January 7th, 2013, 04:44 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,824 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 21 h 1 m
Reputation Power: 1800
Quote:
Originally Posted by lhon12006
sorry if i dont understand the other deep words in proframming
Most of what I said had little to do with programming, but rather how to ask a coherent question. You have not heeded that advice and done nothing to clarify your question. If there is code related to this question, post it in this question directly rather than linking to a different question. The link you gave has been elided so cannot be followed. If that question is in fact the same question, stop creating new threads (unless perhaps you can manage to post a coherent one).

I provided no information about strcmp() that is not already in widely available documentation for that function so it is difficult to see how you could have misunderstood its purpose!

Reply With Quote
  #13  
Old January 8th, 2013, 07:56 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
thank you sir
can you suggest
what is the best use in comparing multiple data or to substitute in strcmp in my program ....

thanks again sir ...

Reply With Quote
  #14  
Old January 8th, 2013, 08:00 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
Quote:
Originally Posted by lhon12006
thank you sir
can you suggest
what is the best use in comparing multiple data or to substitute in strcmp in my program ....

thanks again sir ... :trockon:

Yet again: one pair at a time.

Reply With Quote
  #15  
Old January 9th, 2013, 12:52 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by dwise1_aol
Yet again: one pair at a time.


that could be the case sir in strcmp so it cannot recognize the unsorted data ....

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help in strcmp

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap