what is strcmp do? strcmp work?

Thread Solved

Join Date: Aug 2009
Posts: 25
Reputation: ubi_ct83 is an unknown quantity at this point 
Solved Threads: 1
ubi_ct83 ubi_ct83 is offline Offline
Light Poster

what is strcmp do? strcmp work?

 
0
  #1
Sep 3rd, 2009
i have loaded the string data from file to double array.this is example:
const_array[1][]=a1,b1,c3,
const_array[2][]=a2,b1,c3,
const_array[3][]=a3,b2,c2,
const_array[4][]=a2,b3,c1,
const_array[5][]=a3,b2,c1,

those data need to be compared to this string:
append_test_data.this is also an array and it will be changed randomly by d program.the prob is,my prog just compare to the last data in array,const_array[5][]=a3,b2,c1,
i use this code to compare.
  1. for(int n=1;n<=m;n++)
  2. {
  3. if(strcmp(append_test_data,const_array[n]) == 0)
  4. {
  5. printf("Append data is =%s\n",append_test_data);
  6. printf("constraint is found=%s\n",const_array[n]);
  7.  
  8. getch();
  9. exit(0);
  10.  
  11. }
  12. }

my question is,how is strcmp works?is it compare to the lenght of the string or the string itself?why dose it compare to the last data in array?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,600
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: what is strcmp do? strcmp work?

 
0
  #2
Sep 4th, 2009
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 1
Reputation: contiguous is an unknown quantity at this point 
Solved Threads: 1
contiguous contiguous is offline Offline
Newbie Poster

Re: what is strcmp do? strcmp work?

 
0
  #3
Sep 4th, 2009
Ya.. It compares the strings...
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: akulkarni is an unknown quantity at this point 
Solved Threads: 4
akulkarni akulkarni is offline Offline
Junior Poster in Training

Re: what is strcmp do? strcmp work?

 
0
  #4
Sep 4th, 2009
If u say append_test_data is a String array i dont find an index append_test_data[index] while comparing?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 25
Reputation: ubi_ct83 is an unknown quantity at this point 
Solved Threads: 1
ubi_ct83 ubi_ct83 is offline Offline
Light Poster

Re: what is strcmp do? strcmp work?

 
0
  #5
Sep 7th, 2009
Originally Posted by akulkarni View Post
If u say append_test_data is a String array i dont find an index append_test_data[index] while comparing?
its bcoz i declare it before.do i need to write append_test_data [MAX_LENGTH] everytime i want to use it?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 25
Reputation: ubi_ct83 is an unknown quantity at this point 
Solved Threads: 1
ubi_ct83 ubi_ct83 is offline Offline
Light Poster

Re: what is strcmp do? strcmp work?

 
0
  #6
Sep 7th, 2009
Originally Posted by adatapost View Post
Compare two strings.
is it include this kind of string?
a1,b1,c3 compare to a2,b1,c1

if dat so, why is my code just compare the last last in array?
do u have any comment about my code?
im really stuck wif this thing.....
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: akulkarni is an unknown quantity at this point 
Solved Threads: 4
akulkarni akulkarni is offline Offline
Junior Poster in Training

Re: what is strcmp do? strcmp work?

 
0
  #7
Sep 8th, 2009
is it "a1","b1" ,"c1" or "a1,b1,c1"?
It is a simple concept of array if u have to compare every value u have to give both the entities an index ..[max_length].U have to modify accordingly if the two arrays are not of the same length.It is probably finding only the last value because append_test_data without an index is just one value.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 212
Reputation: MrNoob has a little shameless behaviour in the past 
Solved Threads: 6
MrNoob's Avatar
MrNoob MrNoob is offline Offline
Posting Whiz in Training

Re: what is strcmp do? strcmp work?

 
0
  #8
Sep 8th, 2009
if its multi dimensional array then u have to keep track of the counts ur comparing like for example
for(i=0;i<MAX;i++) //this is a case in which string have same count
if(!strcmp(SzString[i],SzString2[i])) { //do stuff};
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 212
Reputation: MrNoob has a little shameless behaviour in the past 
Solved Threads: 6
MrNoob's Avatar
MrNoob MrNoob is offline Offline
Posting Whiz in Training

Re: what is strcmp do? strcmp work?

 
0
  #9
Sep 8th, 2009
also arrays starts at 0 count not 1
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 25
Reputation: ubi_ct83 is an unknown quantity at this point 
Solved Threads: 1
ubi_ct83 ubi_ct83 is offline Offline
Light Poster

Re: what is strcmp do? strcmp work?

 
0
  #10
Sep 9th, 2009
Originally Posted by akulkarni View Post
is it "a1","b1" ,"c1" or "a1,b1,c1"?
It is a simple concept of array if u have to compare every value u have to give both the entities an index ..[max_length].U have to modify accordingly if the two arrays are not of the same length.It is probably finding only the last value because append_test_data without an index is just one value.
its "a1,b1,c1".
i use const_array as double array so that everytime i just query the row,not the column.
and append_test _data is just a string array.
do u meant with this declaration :
char append_test_data [MAX_LENGTH]="";
i use "" in this array.does it effect?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC