[Solved] strncmp don’t work as it should

strcmp & strncmp functions return 0 if strings are equal. You should do: if (strncmp(frase1, frase3, 4) == 0) … i.e.: char *str1 = “Example 1”; char *str2 = “Example 2”; char *str3 = “Some string”; char *str4 = “Example 1”; if (strncmp(str1, str2, 7) == 0) printf(“YES\n”); // “Example” <-> “Example” else printf(“NO\n”); if … Read more

[Solved] Push pop stack operation in C [closed]

Here you have again some things wrong. Before you create new threads with similar content, stick to one thread. In your code you also never check if malloc fails. It’s always better to do that. For simplicity I’ve omitted these checks in my suggestions. 1. Why do you do S1[0].top=-1; in makeEmpty? create already does … Read more

[Solved] strcmp in a function in c++ [closed]

You can’t insert boolean conditions into the function this way: if (!strcmp( yn , “y” || yn , “Y”)) change the conditions to first evaluate the boolean result of the functions and then perform your logical comparison if (!strcmp(yn , “y”) || !strcmp(yn , “Y”)) Also notice that you’re missing #include <cstring> to use strcmp … Read more

[Solved] How to check if `strcmp` has failed?

There is no defined situation where strcmp can fail. You can trigger undefined behavior by passing an invalid argument, such as: a null pointer an uninitialized pointer a pointer to memory that’s been freed, or to a stack location from a function that’s since been exited, or similar a perfectly valid pointer, but with no … Read more

[Solved] Invalid use of void expression in strcmp

It looks like you want to compare strings after sorting. Assuming your sort function does the right thing, you need to compare the strings after sorting them. sort(string1); sort(string2); val = strcmp(string1, string2); The reason for the error is that your sort function returns void. So you are effectively passing void arguments to strcmp. And … Read more