Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Implementation of strcmp Ask Question. Asked 5 years, 11 months ago. Active 2 months ago. Viewed 36k times. Possible duplicate of Optimized strcmp implementation — Ashish Ahuja. Add a comment. Active Oldest Votes. In C, indexing an array is using pointers. Gianluca Ghettini Gianluca Ghettini 9, 15 15 gold badges 73 73 silver badges bronze badges.
Vlad from Moscow Vlad from Moscow k 18 18 gold badges silver badges bronze badges. And it has another problem: pointers p1 and p2 are needed outside the loop. This is confusing. Superlokkus I am sorry. I do not think we will be able to say something new each other. Show 14 more comments. Daniel B. Larytet Larytet 2 2 silver badges 12 12 bronze badges. Show 1 more comment. Take a step-up from those "Hello World" programs.
Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment?
Please use ide. The strcmp function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2.
Sometimes peoples require to create their own strcmp function for their project. So here in the below section, I shall describe the way to create the strcmp function or you can say that we will see the implementation of strcmp in C. In this C code, we will compare two given string. Note: If possible, you should use strncmp or memcmp. If the first character in both strings is equal, then this function will check the second character, if this is also equal then it will check the third and so on.
We must not use relational operators with string. Yes, you are right it returns a value greater than zero. But when we use a relational operator with the string then the output will be different and it varies system to system. When the first not matching character in left-string s1 has a greater ASCII value than the corresponding character in right-string s2 , then it returns a value greater than zero. When the first not matching character in left-string s1 has a lesser ASCII value than the corresponding character in right-string s2 , then it returns a value less than zero.
0コメント