Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# compare two word?

Posted on 2000-03-22
Medium Priority
196 Views
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
Question by:huhulucy90
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 3

Accepted Solution

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

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

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

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

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

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
###### Suggested Courses
Course of the Month7 days, 7 hours left to enroll

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

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