strcmp

strcasecmp in C returns 156 instead of 0, any ideas why?

I have the following code: printf("num: %d\n", strcasecmp(buf, "h\n")); And I get the following results when I try plugging in different letters: a: -7 g: -1 i: 1 j: 2 h: 156 H: 156 Should strcasecmp not return 0 when buf is equal to H or h? Any ideas why it's returning 156? I need to figure out how to check whether the user types ...

string Comparison

I want to compare two user input strings, but not able to do so... #include "stdafx.h" #include "iostream" #include "string" using namespace std; int _tmain(int argc, _TCHAR* argv0[]) { string my_string; string my_string2; cout<<"Enter string"<<endl; cin>>my_string; cout<<"Enter 2nd string"<<endl; cin>>my_string...

Finding unique elements in an string array in C

Hi, C bothers me with its handling of strings. I have a pseudocode like this in my mind: char *data[20]; char *tmp; int i,j; for(i=0;i<20;i++) { tmp = data[i]; for(j=1;j<20;j++) { if(strcmp(tmp,data[j])) //then except the uniqueness, store them in elsewhere } } But when i coded this the results were bad.(I han...

How to find an element in an array in C

I am trying to find the location of an element in the array. I have tried to use this code i generated for(i=0;i<10;i++) { if (strcmp(temp[0],varptr[i])==0) j=i; } varptr is a pointer which points to array var[11][10] and it is by the definition *varptr[11][10]. I have assigned strings to var[i] and i want to get the "i" n...

strcmp() but with 0-9 AFTER A-Z? (C/C++)

For reasons I completely disagree with but "The Powers (of Anti-Usability) That Be" continue to decree despite my objections, I have a sorting routine which does basic strcmp() compares to sort by its name. It works great; it's hard to get that one wrong. However, at the 11th hour, it's been decided that entries which begin with a number...

Strcmp for cell arrays of unequal length in MATLAB

Is there an easy way to find a smaller cell array of strings within a larger one? I've got two lists, one with unique elements, and one with repeating elements. I want to find whole occurrences of the specific pattern of the smaller array within the larger. I'm aware that strcmp will compare two cell arrays, but only if they're equal in ...

strcmp and wcscmp

Is this if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (wcscmp(FileData.cFileName, L".") != 0) && (wcscmp(FileData.cFileName, L"..") != 0) ) the same as this: if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && wcscmp(FileData.cFileName, L".") && wcscmp(FileData.cFileName, L"..") ) And also ...

strncmp() and if() does not agree...what am I missing?? (raw sockets)

I'm trying to build a simple echo server/client that works on ethernet level(using raw sockets). The server side by itself works and shows all incoming packets on eth0. The client works and sends ethernet packets on eth0 (I checked this with wireshark and can see the packets going out.) I now want to make a filter to only look at the p...

Reorder a PHP array with usort and strcomp: bug

Using usort and strcomp together to order an array by one of its keys has an odd effect: it returns my array with fewer items in it than I put in. The array in my case contains rows representing tasks, and I want to order the rows in the array by the key 'displayorder', which is a number but which I want to be sorted in alphabetical man...

Problem with String compare(strcmp) in C

I'm newbie in C. I want to compare string that I use '#DEFINE' and char buf[256]. This is my code. #define SRV_SHOWMENU "SRV_SHOWMENU" #define SRV_LOGIN_TRUE = "SRV_LOGIN_SUC" #define SRV_LOGIN_FAIL = "SRV_LOGIN_FAIL" #define SRV_REGISTER_OK = "SRV_REGISTER_SUC" #define SRV_REGISTER_FAIL = "SRV_REGISTER_FAIL" char buf[256]; // buff...

compare char* with string macro

Hi I have the following code: #define INPUT_FILE "-i" int main(int argc, char* argv[]) { .... } is there any way in C++ to compare between strings in argv[] and INPUT_FILE? I tried strcmp(argv[1],INPUT_FILE) It compiles but return false each time. Thanks ! ...

Templated Functions.. ERROR: template-id does not match any template declaration

I have written a function template and an explicitly specialized templated function which simply takes in 3 arguments and calculates the biggest among them and prints it. The specialized function is causing an error,whereas the template works fine. But I want to work with char* type. This is the error I get=> error: template-id ‘Max<>...

C++ program crashes

I've this assignment to implement strcmp function. Sometimes it runs okay but other times it crashes. Please help me. #include <iostream> using namespace std; int mystrcmp(const char *s1, const char *s2); int main() { cout<<mystrcmp("A","A")<<endl; cout<<mystrcmp("B","A")<<endl; cout<<mystrcmp("A","B")<<endl; cout...

Can I please get some feedback for this strcmp() function I implemented in C?

Hello. I'm learning C. I find I learn programming well when I try things and received feedback from established programmers in the language. I decided to write my own strcmp() function, just because I thought I could :) int strcompare(char *a, char *b) { while (*a == *b && *a != '\0') { a++; b++; } return ...