Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.    char c = ' ';
  5.    char w_max[2000]; // max word
  6.    char w_temp[2000]; // temp word
  7.  
  8.    for (int i = 0; i < 2000; ++i) {
  9.       /* '\0' => end of line */
  10.       w_max[i] = '\0';
  11.       w_temp[i] = '\0';
  12.    }
  13.  
  14.    int max_len = 0; // max word's length
  15.    int t_len = 0; // temp word's length
  16.    int index = 0;
  17.    while (c != '\n') {
  18.       scanf("%c", &c);
  19.       if (c >= 'a' && c <= 'z') { // ['a';'z']
  20.          t_len += 1;
  21.          w_temp[index] = c; index++; // 'a' -> 0, 'b' -> 1
  22.       } else {
  23.          if (max_len < t_len) {
  24.             max_len = t_len;
  25.             for (int i = 0; i < max_len; ++i) w_max[i] = w_temp[i];
  26.          }
  27.          for (int i = 0; i < t_len; ++i) {
  28.             printf("%c", w_temp[i]);
  29.          }
  30.          printf("\n"); // new line
  31.          index = 0;
  32.          t_len = 0;
  33.          for (int i = 0; i < 2000; ++i) {
  34.             w_temp[i] = '\0';
  35.          }
  36.       }
  37.    }
  38.  
  39.    printf("\n");
  40.    for (int i = 0; i < max_len; ++i) {
  41.       printf("%c", w_max[i]);
  42.    }
  43.  
  44.    return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement