Hello.
What I have to do is:
Take the first half of the input, and output it backwards. Length of the input is 10 or less.
Examples:
123456789 - entered by user;
54321 - result.
abcde - entered by user;
cba - result.
The catch is, that I can only use 2 variables: s and cpt. The only function I can use from string.h is strlen().
I know that there is function strrev() which would do the work, but Im not allowed to use it.
I'm being taught pointers and references now. I know how the & and * work. But I dont know how use them in this task.
If the input was 10 symbols long, I could just output s[4],s[3],s[2],s[1],s[0].
Would be great if someone could point me in the right direction.
I think my English is worse than usually today. Sorry for that.
Thanks.
#include <conio.h>
#include <string.h>
#include <iostream.h>
void main(){
char s[10];
char * cpt;
cpt=s;
// user is not allowed to create arrays with more than 10 symbols
do{
cout<<"Enter the text (number of symbols <=10 )\n";
cin>>s;
cout<<"Length of array: "<<strlen(s)<<"\n"<<"Entered array: "<<s<<"\n";
}while(strlen(s)>10);
cout<<"Middle element of arrray: "<<(strlen(s)+1)/2<<"\n";
cpt=&s[0];
// getting value
cout<<*cpt;
// getting reference
cout<<&cpt;
getch();
}