What is wrong with this switch statement? (C++)?

Also at:
http://pastebin.com/m89z4RhP

#include
#include
#include

utilizing namespace std;

int main()

char line81;

char* ch_ptr;
int digit_count= 0,
lower_count= 0,
punct_count= 0,
space_count= 0,
upper_count= 0,
total_chars;

cout << "Enter a distinct characters:" <<endl;
cin.getline(line, 81);
ch_ptr = line;

when (ch_ptr! = ”)
switch (1)
instance 1:
when (isdigit(*ch_ptr))
++digit_count;
++ch_ptr;
split;

instance 2:
when (islower(*ch_ptr))
++lower_count;
++ch_ptr;
split;

instance 3:
when (ispunct(*ch_ptr))
++punct_count;
++ch_ptr;
split;

instance 4:
when (isspace(*ch_ptr))
++space_count;
++ch_ptr;
split;

instance 5:
when (isupper(*ch_ptr))
++upper_count;
++ch_ptr;
split;

default:
cout << "**** broke";
//null
split;
//end switch
//end while

total_chars = digit_count + upper_count + lower_count + punct_count + space_count;
cout << endl<<"The string contains these:"<<endl <<endl;
cout << "digits:" << digit_count<<endl;
cout << "Lowercase words:" << lower_count<<endl;
cout << "Uppercase words:" << upper_count<<endl;
cout << "Space characters:" << space_count<<endl;
cout << "Punctuation chars:" << punct_count<<endl;
cout <<" — – — – :- – – – – – – – -" <<endl;
cout << "Total characters:" << total_chars;
cout <<endl<<endl<<endl;
system(“PAUSE”);

gain 0;

replace this particular
when (ch_ptr! = ”)
together with
when (*ch_ptr! = ”)

after which:

small fix:
//——————————
default:
cout << "**** broke";
//null
++ch_ptr;
split;
//end switch
//——————————
// lengthier fix:
// remove all of the ++ch_ptr terms infront with the break statements after which:
split;
//end switch
++ch_ptr;
//——————————

Otherwise you get in the endless loop the minute your computer code
sinks into the default record! of your switch, mainly because no additional
character are going to be examined, but only the one in the actual default affirmation!!!!!!

That’s a strong utter perversion of the switch declaration.The way you could have the switch() in addition to its cases build completely obviates the use.On the internet is the if-else-if sieve devoid of the break claims, like this particular:

when (isdigit(*ch_ptr))
++digit_count;
++ch_ptr;

altogether different if (islower(*ch_ptr))
++lower_count;
++ch_ptr;

And WHEN I don’t observe anything “wrong” considering the code, unless a person’s compiler will be complaining in which it’s senseless to complete a switch() using a constant price.Which it is really right regarding.

Expectation that assists.

Can’t view anything wrong considering the switch statement, but you would need to dereference the particular pointer inside while loop regarding it to obtain the end with the string properly otherwise it’s going to just carry on (i.at the while(ch_ptr! = ”) must be while(*ch_ptr! = ”) ).

Leave a Reply