Hi i just need a help to delete words consecutive repeated
like :
text :
hi hi how are are you you
print :
hi how are you
Hi i just need a help to delete words consecutive repeated
like :
text :
hi hi how are are you you
print :
hi how are you
What is your idea, and what have you tried?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Start with a simpler program to just print each word.
Then you can expand to comparing adjacent words.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
the idea is that , i've seen a question that want me to make a program with three function , one of them is to delete extra spaces , and the second to capitalize the first character in the first word and the delete the other capital characters ,and the third that want me to to delete consecutive repeated words only the consecutive ones. like : the great great the , print : the great the
That's not "your idea", that's the requirements. What I meant is how do you intend to do this? How are you going to read the words?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
using an array
Okay, so what is your current code?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i didnt do the main yet , i just did the two functions alone as a main , just this one the third i didn't do.
Code:Code:#include <stdio.h> #include <conio.h> #include <string.h> int main() { char TextBefore[100], TextAfter[100]; int j = 0, i; printf("Enter a String \n"); gets(TextBefore); /* Skips all spaces before first characters */ while (TextBefore[j] == ' ') { j++; } for (i = 0; TextBefore[j] != '\0'; j++) { if (TextBefore[j] == ' ' && TextBefore[j - 1] == ' ') { continue; } TextAfter[i] = TextBefore[j]; i++; } TextAfter[i] = '\0'; printf("String without extra spaces\n%s", TextAfter); getch(); return 0; } #include <stdio.h> #include <conio.h> #include <string.h>
Code:int main() { char TextAfter[100]; int i = 0; gets(TextAfter); if (TextAfter[i] >= 'a' && TextAfter[i] <= 'z') TextAfter[i] -= 32; for (i = 1;i < strlen(TextAfter); i++) { if (TextAfter[i] >= 'A' && TextAfter[i] <= 'Z') TextAfter[i] += 32; } puts(TextAfter); getch(); return 0; }
Code:#include <stdio.h> #include <conio.h> #include <string.h> int main() { char check[100], TextAfter[100]; int x, j = 0, i = 0, flag = 1, count = 0, c, z; gets(TextAfter); if (TextAfter[i] == ' ') i++; while (TextAfter[i] != ' ') { check[j] = TextAfter[i]; count++; j++; i++; } j = 0; x = i; if (count != 0) { for (z = 0; z < count; z++) { if (TextAfter[x] != check[j]); flag == 0; x++; j++; } if (flag = 1) { c == i + count; for (z = 0; z < count; z++) { TextAfter[i] == TextAfter[c]; } } j = 0; } printf("String without extra spaces\n%s", TextAfter); getch(); return 0; }
You're getting somewhere, definitely. I would just make sure that you compile in such a way that catches mistakes like confusing = for == and vice versa.
It looks like you have the meaning of these operators backwards.Code:C:\Users\jk\Desktop>gcc -Wall -std=c99 -c foobar.c foobar.c: In function 'main': foobar.c:31:13: warning: statement with no effect [-Wunused-value] flag == 0; ^ foobar.c:37:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if (flag = 1) ^ foobar.c:39:13: warning: statement with no effect [-Wunused-value] c == i + count; ^ foobar.c:42:19: warning: statement with no effect [-Wunused-value] TextAfter[i] == TextAfter[c]; ^ foobar.c:42:44: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized] TextAfter[i] == TextAfter[c]; ^