#include <iostream>
#include <string.h>
usingnamespace std;
void erasefirstsmall(char t[])
{
int position=0;
int small;
97<=small<=122; //What is this doing here? It does nothing at all...
while( t[position]!=0 && t[position]!=small)
{
position++;
}
if( t[position]== mala )
{
delete &t[position], &t[position+1]; //What is the point of this? You can't delete a single char like this
//Also it only uses &t[position+1] due to the comma.
}
}
int main()
{
int n=0;
char text [n]; //illegal
cout<<"introduce text"<<endl;
cin>> text; //Buffer overflow
erasefirstsmall (text);
cout<< text;
system ("PAUSE");
}
Only delete the first element pointed by new, or you will have big problems!
That is nonsensical (did you mean (97 <= small) && (small <= 122), and it doesn't even do anything. What exactly are you trying to do here? I see that you've used 97 and 122 as the numerical limits of lower case letters, but what's supposed to happen if small is less than 97 or greater than 122? It doesn't do anything.
What does "erase" mean? If the input is
EFsDFR
should the output be
EF DFR or EFDFR ?
1 2 3 4
int n=0;
char text [n];
cout<<"introduce text"<<endl;
cin>> text;
This code makes an array of char, of size zero. It can hold ZERO letters. Why would you make an array that can hold ZERO letters, and then try to put letters into it? This makes no sense.
char text [n];
This is a variable length array. They are forbidden in C++. Your arrays must be a fixed size.
You're coding in C++. Time to use proper C++ strings.
1 2 3 4 5 6 7 8 9 10 11
//userInput is a std::string holding the user's entered word
for (int i = 0; i< userInput.length(); ++i)
{
if(islower(userInput[i]))
{
userInput.erase(i,1);
break;
}
}