Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int strlen(const char str[]) {
- int length = 0;
- while (*str++) {
- ++length;
- }
- return length;
- }
- void strcpy(char target[], const char source[]) {
- while (*target++ = *source++);
- }
- int strcmp(const char lhs[], const char rhs[]) {
- while (*lhs || *rhs) {
- if (*lhs++ != *rhs++) {
- return *(lhs - 1) - *(rhs - 1);
- }
- }
- return 0;
- }
- int main() {
- const int maxLen = 100;
- char str1[maxLen];
- char str2[maxLen];
- gets_s(str1);
- gets_s(str2);
- printf("strlen(str1) = %d\n", strlen(str1));
- printf("strlen(str2) = %d\n", strlen(str2));
- printf("strcmp(str1, str2) = %d\n", strcmp(str1, str2));
- strcpy(str2, str1);
- printf("str1 = %s\n", str1);
- printf("str2 = %s\n", str2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement