Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

compare two word?

Posted on 2000-03-22
5
Medium Priority
?
199 Views
Last Modified: 2010-04-15
if I want to input a 4-letter word on the commond line,
and then compare it with "abcd", what should I do?
I mean, how to transfer this input word to a varible
in the beginning, like this way: word[4] = atoi(argv[1]); ?

thank you very much!

   
0
Comment
Question by:huhulucy90
5 Comments
 
LVL 3

Accepted Solution

by:
3rsrichard earned 150 total points
ID: 2646665
int main(int argc, char* argv[])
{

if( strcmp(argv[1],"abcd")
{  // they match
} else {
// they don't match
};
0
 

Author Comment

by:huhulucy90
ID: 2647370
actually, it is a guessing question,
how can I get the total number of guesses if
I want to find the word that is inputed on the
commond line.
thanks!
0
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 2647382
sounds like a school assignment to me, so I won't give any code. But basically, you want to use a count variable, initialized to 0. Every time the user inputs a word, increment the count variable. Keep doing this until the strings match (as shown in 3rsrichard's comment). Then the count variable contains the number of guesses.
0
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 2647396
..and besides strcmp(), there's also strncmp(s1, s2, n), where it will only compare the 1st n characters of the strings. Bot of these are case sensitive comparisons. For a case insensitive compare, you can use strcasecmp() or strncasecmp()
0
 

Expert Comment

by:jpjpjp
ID: 2647694
note that strcmp will return 0 if the words are the same, so the if should be

if (! strcmp (..., ...))
{
  /* same words */
}
else
{
   /* diff */
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question