EDIT:Changed the title, refer to reply 5 for updated info on the issue.
I'm trying to create a program that switches all lowercase letters to uppercase, "removes" punctuation, and "removes" excess spaces from a char array, but it isn't working correctly, here's the code.
#include <iostream>
#include <algorithm>
#include <locale>
#include <string>
#include "conio.h"
#include <stdio.h>
#include <ctype.h>
usingnamespace std;
int main(){
int i = 0;
int istate;
bool uppercase = true;
bool punctuate = false;
bool removespace = false;
bool state = false;
int next = 1;
char test[] = " hello# >?world> ";
char c = test[i];
while(uppercase == true){
c = test[i];
if (islower(c)){c = toupper(c);}
test[i] = c;
i++;
if(i == 17){i = 0;next = 1;uppercase = false;punctuate = true;}
}
while(punctuate == true){
c = test[i];
if (ispunct(c)){c = ' ';}
test[i] = c;
i++;
if(i == 17){i = 0;next = 1;punctuate = false;removespace = true;}
}
while(removespace == true){
c = test[i];
if((test[i] == ' ' ) & (test[next] == ' ')){
istate = i;
state = true;
while(state == true){
c = test[next];
if(i == 17){
i = istate - 1;
next = istate;
c = test[i];
state = false;
removespace = false;}
else {
test[i] = c;
i++;next++;}}}
test[i] = c;
i++;next++;}
cout << test << endl;
_getch();
}
It converts to uppercase, and removes the punctuation just fine, but it doesn't remove all of the spaces. The output should be "HELLO*WORLD", but it only gives me "HELLO***WORLD",which means it only removes one of the four spaces, help would be appreciated.
NOTE: asterisks stand in for spaces because I can't display more than one space in a row.
That seems to complicated for my level, I barely understood what happened in the example.EDIT: that was a response to albatross, not godpyro
EDIT2: Never mind, I get it now, but how would I use the unique function to search for a specific character? That example gets rid of all repeating characters.
You could adjust the comparing function to also check to see if the character is some specific character. That would make the specific character a constant, though, unless you made a functor or something.
EDIT: Okay screw vectors, I just want to know why my original code doesn't work, I've done some testing and apparently, even though both the current character and next character are both spaces, it won't activate the code.