Hi all,
i made some java few time ago and i'm now studying C++
here is a simple program i've been working on to learn about it but the fact is for some days now i can't figure why it doesn't work...
in fact i just want to create an array of strings, noms[10]
my problem is that the first name will be stored all right in " noms[0] " , but then if i add a second name, it will be stored both in " noms[0] " and " noms[1] " ... and again same problem with a third name in noms[0] noms[1] and noms[2] ...
perhaps it's a real simple one but i don't really understand why data will go on " noms[0] " if i'm considering the address of " noms[1] "
thank you
vincent
#include <iostream>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <istream>
using namespace std;
int j=0;
char *noms[10];
char **ptr;
void add() {
char name[20];
cout << "Enter a name" << "\n";
cin >> name;
*ptr = name;
cout << "voici noms[" << j << "] :" << noms[j] << "\n";
cout << "voici noms[0]" << noms[0] << "\n";
return;
}
int main()
{
int x;
ptr = &noms[0];
while (j<11) {
cout << " Enter your choice :" << "\n";
cin >> x;
if ( x ==1 ) {
add();
j++;
ptr++;
}
}
}