Skip to content

Commit

Permalink
Aula 11 - Problema 5
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Pereira committed Feb 18, 2016
1 parent ddea728 commit b590826
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Aula_Pratica_11/Problema_5.c
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
// TODO do
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
char c, *max, *p;
int n = 0, l = 0, i = 0;
printf("Frase? ");
max = (char *) malloc(sizeof(char));
p = (char *) malloc(sizeof(char));
while (scanf("%c", &c) == 1) {
if (c == ' ' || c == '\n') {
if (strlen(p) > strlen(max)) {
max = (char *) realloc(max, sizeof(char) * strlen(p));
strcpy(max, p);
}
n++;
i = 0;
if (c == '\n') break;
}
else {
p = (char *) realloc(p, sizeof(char) * (i + 1));
p[i] = c;
l++;
i++;
}
}
printf("Numero de palavras: %d\n", n);
printf("Palavra maior: %s\n", max);
printf("Comprimento medio: %.1f\n", (float) l / (float) n);
return 0;
}

0 comments on commit b590826

Please sign in to comment.