Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int mystrlen(const char * str)
- {
- int len;
- for (len = 0; str[len] != '\0'; len++);
- return len;
- }
- int main() {
- int i = 0, j, k, max = 0, flag = 0, z=0, start=0;
- int len;
- char *word = nullptr, *max_word = nullptr, *temp = nullptr;
- puts("Input text with the $ in the end:");
- max_word = (char*)malloc(sizeof(char) * 1);
- temp = (char*)malloc(sizeof(char) * 1);
- word = (char*)malloc(sizeof(char) * 1);
- for (i = 0; (word[i] = getchar()) != '\n'; i++);
- word[i] = '\0';
- len = mystrlen(word);
- for (i = 0; i < len+1; i++) {
- //if (start == 0) {
- // for(int j = i; word[j] != ' ' && word[j] != ',' && word[j] != '\n' && word[j] != '.' && word[j] != '!' && word[j] != '?' && word[j] != ';' && word[j] != ':' && word[j] != '\0'; j++){
- // }
- // j--;
- // max_word = (char*)realloc(max_word, sizeof(char) * j);
- // max_word[j] = '\0';
- // for (int t = 0; t < j; t++) {
- // max_word[t] = word[t];
- // }
- //}
- if (word[i] != ' ' && word[i] != ',' && word[i] != '\n' && word[i] != '.' && word[i] != '!' && word[i] != '?' && word[i] != ';' && word[i] != ':' && word[j] != '\0') {
- continue;
- }
- else {
- z = i - z;
- if (word[i + 1] == ' ') i++;
- temp = (char*)realloc(temp, sizeof(char) * z);
- temp[z] = '\0';
- int m = start;
- for (int t = 0; t < z; t++) {
- temp[t] = word[m];
- m++;
- }
- for (k = 0; k < z; k++) {
- for (j = k; j < z; j++) {
- if (temp[j] == temp[k] && j != k)
- flag = 1;
- }
- if (k == z - 1 && flag == 0 && k > max) {
- max = k;
- int lent = mystrlen(temp);
- max_word = (char*)realloc(max_word, sizeof(char) * lent);
- temp[lent] = '\0';
- max_word = temp;
- }
- }
- z = i + 1;
- start = i + 1;
- flag = 0;
- }
- }
- printf("%s\n", max_word);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement