Advertisement
Niloy007

String

Nov 1st, 2020
1,717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5.  
  6. int main() {
  7.     char strOne[20];
  8.     char strTwo[20];
  9.     gets(strOne);   // input
  10.     gets(strTwo);
  11.  
  12.     int check = strcmp(strOne, strTwo);
  13.  
  14.     if(check == 0) {
  15.         printf("Both strings are same\n");
  16.     } else if(check > 0) {
  17.         printf("First string is greater than the sceond one\n");
  18.     } else if(check < 0) {
  19.         printf("Sceond string is greater than the first one\n");
  20.     }
  21.  
  22.     // logic of finding length of a string
  23.     // int i = 0;
  24.     // int length = 0;
  25.     // while (strOne[i] != '\0') {
  26.     //  length++;
  27.     //  i++;
  28.     // }
  29.     // printf("%d\n", length);
  30.  
  31.     // int lenOne, lenTwo;
  32.     // lenOne = strlen(strOne);
  33.     // lenTwo = strlen(strTwo);
  34.     // printf("Length of strOne = %d\n", lenOne);
  35.     // printf("Length of strTwo is = %d\n", lenTwo);
  36.  
  37.     // printf("Before Concat:\n");
  38.     // printf("String One = %s\n", strOne);
  39.     // printf("String Two = %s\n", strTwo);
  40.  
  41.     // strcat(strTwo, strOne);
  42.     // strcpy(strThree, strTwo);
  43.  
  44.     // strcpy(strTwo, strOne);
  45.     // printf("String Three = %s\n", strThree);
  46.  
  47.     return 0;
  48. }
  49.  
  50. // int main() {
  51. //  char str[20];
  52. //  gets(str);
  53. // scanf("%s", str);    // Input using scanf
  54.  
  55. //  printf("%s\n", str);
  56. // }
  57.  
  58.  
  59. /*
  60.     '\0' -> null charachter
  61.  
  62.     1. Basic Concepts about string in c.
  63.     2. Input a string.
  64.     3. Print a string.
  65.     4. Some functions related to string
  66.         -> strcpy(one, two);   
  67.         -> strcat();
  68.         -> strlen();
  69.         -> strcmp();
  70. */
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement