View Single Post
Join Date: Dec 2008
Posts: 25
Reputation: Jenniferlinn is an unknown quantity at this point 
Solved Threads: 1
Jenniferlinn Jenniferlinn is offline Offline
Light Poster

Re: sorting characters in a string... help!!!!

 
0
  #2
Jan 1st, 2009
Here is an example to implement strcmp():

int strcmp ( const char * str1, const char * str2 );



<cstring>

Compare two strings

Compares the C string str1 to the C string str2.
This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminanting null-character is reached.

Parameters

str1
C string to be compared.
str2
C string to be compared.

Return Value
Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.

Example

/* strcmp example */
#include <stdio.h>
#include <string.h>

int main ()
{
char szKey[] = "apple";
char szInput[80];
do {
printf ("Guess my favourite fruit? ");
gets (szInput);
} while (strcmp (szKey,szInput) != 0);
puts ("Correct answer!");
return 0;
}

Output:


Guess my favourite fruit? orange
Guess my favourite fruit? apple
Correct answer!
Reply With Quote