Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C command line arguments input

enter image description here

Hi! So I was playing with command line arguments to get used to work with them. I tried to make the program to say valid if the argument I would write is the same as the one saved in the variable.
Any ideas why this doesn’t work?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use strcmp to compare strings.
In C, you cannot use == and != to check for string equality.

What you want is:

if (strcmp(argv[1], pass))   // Use String Compare (strcmp) to test equality.  
                             // Returns 0 if strings are equal
                             // Returns non-zero if strings are different.
{
    printf("Invalid\n");
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading