Witam,
Bardzo proszę o pomoc. Łamię sobie głowę nad ćwiczeniem trzeci dzień, wydaje mi się że nic już nie wymyślę i zwracam się z prośbą o pomoc do Was.
Program ma przyjąć string od użytkownika i wydrukować string odwrotnie używając pointerów. Czy ja jestem w ogóle blisko?
Przy próbie uruchomienia programu wyskakują mi następujące błędy:
main.cpp: In function ‘int main()’:
main.cpp:38:29: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
cout << reverseStr(pString) << endl;
^
main.cpp:8:8: note: initializing argument 1 of ‘char* reverseStr(char*)’
char * reverseStr(char * pString) // this function reverses the string
^
Oto mój kod:
#include <string.h>
#include <iostream>
using namespace std;
char * reverseStr(char * pString) // this function reverses the string
{
{
return NULL;
}
char * pStart = pString;
char * pEnd = pStart + strlen(pString) -1;
while (pEnd > pStart)
{
char temp = *pStart;
*pStart = *pEnd;
*pEnd = temp;
pStart++;
pEnd--;
}
return pString;
}
int main()
{
char pString;
char run_me_again_check; // for mutiple running of program
bool run_me_again = true;
while (run_me_again)
{
cout << "Please enter the string to reverse : ";
cin >> pString;
reverseStr;
cout << reverseStr(pString) << endl;
cout << "One more time? (Y/N) ";
cin >> run_me_again_check;
if (run_me_again_check == 'Y' || run_me_again_check == 'y')
{
run_me_again = true;
}
else
{
run_me_again = false;
}
}
return 0;
}