Pointers

Hi, I need help with my program. It needs to use pointers and meet the following criteria...having the user input a 12 character word. Store this word in a char*. Next ask the user for an integer.
Manipulate the char* to shift the word to the left by the integer amount:

>Enter a Word:
Hello World
>Enter a Number:
4

Your Shifted Word is:
rldHello Wo

>Enter a Word:
Teddy Bear
>Enter a Number:
7

Your Shifted Word is:
y BearTedd



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main ()
{
    int n;
    int number [n];
    char * word;
cout << "Please enter a 12 letter word" << endl;
cin >> word;
cout << "Please Enter an integer" << endl;
cin >> n;

word[n] = 0;
word--;

return 0;

Thank you
}
char * word;
declares a pointer which points to nowhere, you must have an array ( allocated automatically or dynamically ) to store your string
So would something like this be on the right track?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main ()
{
    int n;
    int number [n];
    char * word;
    char word [word];
cout << "Please enter a 12 letter word" << endl;
cin >> word;
cout << "Please Enter an integer" << endl;
cin >> n;

word[n] = 0;
word--;

return 0;

}


But then i dont know what to do
Not really. For starters, you're using the identifier "word" for two different objects, and you're apparently trying to use a pointer as the size of an array.
@koutsos1 (OP) don't post the same problem multiple times: http://www.cplusplus.com/forum/general/26649/
Topic archived. No new replies allowed.