Skip to content

Commit

Permalink
strcmp 구현
Browse files Browse the repository at this point in the history
strcmp 구현
  • Loading branch information
hyejun0608 authored Jun 17, 2020
1 parent 7177a5f commit e1b2175
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions strcmp 구현.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>

int strcmp(char* dest, char* src) {
int i;
for (i = 0; dest[i]||src[i]; i++) {
if (dest[i] > src[i]) {
return 1;
}
else if (dest[i] < src[i]) {
return -1;
}
}
if (dest[i]) return 1;
else if (src[i]) return -1;
return 0;
}

int main() {
char dest[100], src[100];
int i;
gets(dest);
gets(src);
printf("%d", strcmp(dest, src));
}

0 comments on commit e1b2175

Please sign in to comment.