Well I've been picking at a program for some time now, and I've come to a obstacle.... I'm looking to have the program take in so many characters. ( mostly sentences), and out the length of the sentence, and what letters or if a space occurs at points 2 4 6 8 10. In the string... So if the sentence is "Hello welcome to Yatatata.... etc". it should print the length being 32 in length. ( using the strlen function) However I can't find a function to print those specific values... ( e, l, , e, c)
#include <iostream>
usingnamespace std;
int main ()
{
char* str;
// somehow fill it with a sentence here
// Ouput the length
cout << "Length: " << strlen(str) << "\n";
for (int i=2; i<=10; i+=2)
{
// Output the start of the line
cout << "Element " << i;
if (str[i]==' ') cout << " is a space\n"; // If it is a space
else cout << " is: " << str[i] << "\n"; // Otherwise
}
}
If you wanted to do n multiples of x starting from x, the loop would look like this:
1 2 3 4 5 6 7
for (int i=x; i<=(x*n); i+=x)
{
// Output the start of the line
cout << "Element " << i;
if (str[i]==' ') cout << " is a space\n"; // If it is a space
else cout << " is: " << str[i] << "\n"; // Otherwise
}