training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

ncmp2s.c (541B)


      1 /* Exercise 8.10 */
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 
      6 int main(void)
      7 {
      8    char s1[10];
      9    char s2[10];
     10    int val, num;
     11 
     12    printf("Give me a string (s1): ");
     13    gets(s1);
     14    printf("Give me another string (s2): ");
     15    gets(s2);
     16    printf("How many characters want to compare?: ");
     17    scanf("%d", &num);
     18 
     19    val = strncmp(s1, s2, num);
     20    printf("s1 is ");
     21 
     22    if(!val)
     23       printf("equal to");
     24    else if(val < 0)
     25       printf("less then");
     26    else
     27       printf("greater then");
     28 
     29    printf(" s2\n");
     30 
     31    return 0;
     32 } /* E0F main */
     33