i need to do interactive program
that have 3 option
1-entter string and function will print the first letter from each line
if string is empty print "empty string"(i haee problem with this function) please help.
2-i still thinking how to do it
3-exit the program
all the program in endless loop.
guys how to delete the string in option 1
beacuse when i press option 1 and write adi was here
its print awh
and then i want to do function 1 again and put empty string
its print "empty string" and still print awh
The line void main() should be int main(). void is no longer an accepted way of writing line 5. Also just before the closing brace of main you need the line return 0;.
You have included the header file <string>, but on line 8 you are using a char array when all you need is std::string str{ "" };. The { "" } initializes the string to an empty string and you should always initialize your variables.
Case 0: should not exit(0):, but set flag to false exit the switch then exit the while loop to end the program.
Line 26 would work better after line 22.
Not sure how you arrived at a value for "len", but using strings the if statement could simply say: if (str.length() == 0).
Lines 17 and 24 should not be there. Only one is need above the while loop. If you do not receive a redeclaration error because you are trying to redeclare the same variable each time through the while loop it will likely cause other problems. One of which is not reaching case 2.
Have you learned about std::strings yet? Much better to use than a pointer to a C style char array.
Hope that helps,
Andy
Edit: I found that line 17 should be moved to the top of the while loop say line 9 to work with func1 properly. And the system("pause"); should be put before each break statement.