[ create a new paste ] login | about

Link: http://codepad.org/8DBRUAGf    [ raw code | output | fork ]

C, pasted on Jul 19:
#include <stdio.h>
int compare_string(char *a, char *b) {
  char *p, *q;
  int f = 1;
  for (p = a, q = b; *p != '\0' && *q != '\0'; p++, q++)
    if (*p != *q) {
      f = 0;
      break;
    }
  if (*p == *q)
    return f;
  else
    return 0;
}

int main() {
  char s1[] = "abc";
  char s2[] = "abc";
  char s3[] = "xyz";
  char s4[] = "abcxyz";
  printf("s1-s2 : %d\n", compare_string(s1, s2));
  printf("s1-s3 : %d\n", compare_string(s1, s3));
  printf("s1-s4 : %d\n", compare_string(s1, s4));
  printf("s4-s1 : %d\n", compare_string(s4, s1));
  return 0;
}
/* end */


Output:
1
2
3
4
s1-s2 : 1
s1-s3 : 0
s1-s4 : 0
s4-s1 : 0


Create a new paste based on this one


Comments: