Solved

compare two word?

Posted on 2000-03-22
5
186 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 50 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adjust Mfcapp 29 155
In C, why can't I shift a 64-bit integer more than 32 bits? 13 193
Read file descriptor 3 in C 14 102
C#, VS15, StructLayout 1 116
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now