Advertisement
Neo_Feo

Horor_CPP4_Done

Sep 17th, 2023
803
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void scanWord(char ** buff){
  6.     char *buffer = NULL;
  7.     size_t bufsize = 0;
  8.     ssize_t bytesRead = getline(&buffer, &bufsize, stdin);
  9.  
  10.     if (bytesRead == -1) {
  11.         perror("getline");
  12.         return;
  13.     }
  14.  
  15.     *buff = (char *) malloc(bytesRead * sizeof(char));
  16.     strcpy(*buff,buffer);
  17.     free(buffer);
  18. }
  19.  
  20. int main()
  21. {
  22.     char * word1, * word2;
  23.  
  24.     char* buff = NULL;
  25.     printf("Introduceti primul cuvant: ");
  26.     scanWord(&word1);
  27.  
  28.     printf("Introduceti al doilea cuvant: ");
  29.     scanWord(&word2);
  30.  
  31.     size_t lenght1 = strlen(word1);
  32.     size_t lenght2 = strlen(word2);
  33.  
  34.     if(lenght1 > lenght2){
  35.         printf("Primul cuvant este cel mai lung");
  36.     }else{
  37.         printf("Al doilea cuvant este cel mai lung");
  38.     }
  39.  
  40.     free(word1);
  41.     free(word2);
  42.     return 0;
  43. }
  44.  
Advertisement
Comments
  • Neo_Feo
    9 days
    # text 0.21 KB | 0 0
    1. https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=Untitled%20Diagram.drawio#Uhttps%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D1zgsXPJlr41KDYAybxi2sQuZdJ82qEXe3%26export%3Ddownload
Add Comment
Please, Sign In to add comment
Advertisement