Tring to use a function read a sentence

and cout << it backwards but divided by each words... Example

Hi how are you? would become
iH woh era ?uoy

Here is where i am so far... It s in french... but i does not work... :(

It is the first time I use a Function... and not even sure if my backwards read is ok... I am trying hard, but would really need help. I am so far as that when I compile... it cannot open the program...

#include <iostream>
#include <conio.h>
#include <iomanip>
#include <string.h>

using namespace std;

//Déclariation des prototypes des fonctions locales
char Mot(char *pInverse);


//---------------------------------------------------------------------------
//Fonction principale du programme
//Descritption: Lit une ligne de 80 caracteres maximum et affiche la ligne en
// inversant les lettres de chaque mot.
//---------------------------------------------------------------------------
void main()
{
//
//Définition des variables locales
//
char Phrase; //La ligne de 80 caracteres maximum


//
//Instructions
//

cout<<"SVP entrer une ligne de texte contenant un maximum de 80 caracteres et qui se termine par un pochar: \n";
cout<<"--------------------------------------------------------------------------------------------------\n\n";

//
// Saisie de la phrase
//

cin >> Phrase;


//
//Vérifier si la lecture de l'information s'est bien passée
//

if(cin.fail())
{
cout<<"\n\n Erreur --- Votre phrase contient plus de 80 caracteres. \n\n";
}else
{
while(Phrase =' ') //Valide si un espace () ou un pochar (.) est fait
{
if(Phrase = '.')
{
}
}cout << Mot(&Phrase) << "\n";

}



//
//Resultat demande
//

//cout <<

//
//Fin du programme
//

cout <<flush;
_getch();

}


//---------------------------------------------------------------------------
//Fonction: Inverse
//Descritption: Inverser chaque mot par adresse
//---------------------------------------------------------------------------

char Mot(char* pEndroit,char* pInverse, int pos)

{
char lreturn;
int index = 0;

int len = strlen(input);
for(int i = pos; i < len; i++)
{
output[index] = input[i];
index++;
}
output[index] = 0;

lreturn = *pInverse;
return pInverse;

}

Your function prototype is different from the implementation of your function. At the top you have char Mot(char *pInverse); but at the bottom you declare it as char Mot(char* pEndroit,char* pInverse, int pos). These need to have the same number and type of arguments.
ok thanks I'll try this!
There is already an STL algorithm for reversing the elements of a container. Check it out:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main( int argc, char* args[] ) {

    // read in a sentence
    string sentence;
    cout << "Enter a sentence: " << endl;
    getline( cin, sentence );

    // seperate the sentence into "words" delimited by whitespace
    string word;
    istringstream sin( sentence );
    while( sin >> word )
    {
        // reverse the characters
        reverse( word.begin(), word.end() );

        // output the word followed by a space
        cout << word << " ";
    }
    // output a newline
    cout << endl;

    return 0;
}
Topic archived. No new replies allowed.