+ 1

Hi guys! Can you help me please? C

/* this program has to print all words that have double letters but if there're no such words "none" must be printed but only once! for example "the weather is good the grass is green" the output has to be" good grass green" for example "the weather rainy" the output has to be "none" but it prints every time no such word is found */ #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char sentence[200] = { 0 }; printf("Enter your sentence:"); fgets(sentence, 200, stdin); char *word; char limits[] = " , ."; printf("Unique words:"); int n; for (word = strtok(sentence, limits); word; word = strtok(0, limits)) { int check[200] = { 0 }; char* uniqWord = word; for (; *word; ++word) { if (check[*word]++) { printf("none" ); break; } n = 0; if (*word && *(word + n) == *(word+n+1)) { printf("%s ", uniqWord); n++; }} } return 0; }

20th Oct 2021, 10:38 AM
Julia Sagan
Julia Sagan - avatar
3 Answers
0
Hi, if you have solved it then it's good. If not, you can check out my solution. This is not very elegant. I didn't use strtok() and any memory allocation other than the initial buffer. The code doesn't do error checking so it expects the input should be accurate. Let me know if it breaks at some point. https://code.sololearn.com/cQi6KEdLJD0Y
21st Oct 2021, 2:09 PM
Flash
0
Write an else statement to print none, if no such word is found.
21st Oct 2021, 9:22 AM
Karthik Balakrishnan
0
Thank you so much!
23rd Oct 2021, 5:27 PM
Julia Sagan
Julia Sagan - avatar