Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX_WORD_SIZE 100
- #define MAX_WORDS 10
- int main()
- {
- char text[MAX_WORD_SIZE];
- char splitted[MAX_WORDS][MAX_WORD_SIZE];
- int splitted_i;
- char shortestWord[MAX_WORD_SIZE];
- char longestWord[MAX_WORD_SIZE];
- gets(text);
- ld_split(text, splitted, &splitted_i);
- strcpy(shortestWord, splitted[0]);
- strcpy(longestWord, splitted[0]);
- int i = 1;
- for (; i < splitted_i; i++) {
- if (ld_strlen(splitted[i]) > ld_strlen(longestWord))
- strcpy(longestWord, splitted[i]);
- if (ld_strlen(splitted[i]) < ld_strlen(shortestWord))
- strcpy(shortestWord, splitted[i]);
- }
- printf("Najduza: \"%s\" (%i)\n", longestWord, ld_strlen(longestWord));
- printf("Najkraca: \"%s\" (%i)\n", shortestWord, ld_strlen(shortestWord));
- return 0;
- }
- int ld_strlen(char *text) {
- int i = 0;
- while (text[i] != 0)
- i++;
- return i;
- }
- void ld_split(char text[MAX_WORD_SIZE], char splitted[MAX_WORDS][MAX_WORD_SIZE], int *splitted_num) {
- int splitted_j = 0, splitted_i = 0;
- int i = 0;
- for (; i < ld_strlen(text) + 1; i++) {
- if (text[i] == ' ' || text[i] == 0) {
- splitted[splitted_i++][splitted_j] = 0;
- splitted_j = 0;
- }
- else
- splitted[splitted_i][splitted_j++] = text[i];
- }
- *splitted_num = splitted_i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement