Avatar of Ahmed Ali
Recommends
on
GitHubGitHub

I think Github is the most important thing, so take good care of it, and share your most important programs on it with others, this helps to raise your efficiency through the feedback of others. with my Greetings.

READ MORE
8 upvotes·1 comment·199K views
Daksh Sharma
Daksh Sharma
·
February 9th 2022 at 4:04PM

Thank you so much

·
Reply
Recommends
on
C langC lang

Dear, Yusuf You can't use if statement to compare two strings, but you can use strcmp() function which means string compare The behavior of strcmp function is: If (string1 < string2)? Then: return a negative value. If (string1 > string2)? Then: return a positive value.

If(string1 == string2)? Then: return (0).

So, you can modify this statment to: if(strcmp(name,"Yousef") != 0) printf("name undefined\n");

else printf("find name");

But, In this case there is one logic problem that (strcmp) function don't ignore the letter case. For example: If you input name : yousef

The first letter here (y) is small, but in the comparing statement above is capital, So the result will be "name undefined", but in fact "yousef" = "Yousef".

To solve this problem you should use stracasecmp() function. This function ignore the letter case while comparing. The code will be: if(strcasecmp(name,"Yousef") != 0) printf("name undefined\n");

else printf("find name");

Attention: Include string libreary after using these functions to skip any problem may be found.

include

may Allah bless you ^_^

READ MORE
3 upvotes·1 comment·95K views
Ahmed Ali
Ahmed Ali
·
February 5th 2022 at 3:57PM

But you can use fgets() function Instead of gets(), because - The fgets () function is safer to use. - It checks the bounds, i.e., the size of the buffer and does not cause overflow on the stack to occur. - The gets () function does not check the bounds.

·
Reply