Hi . what is my error in program
#include <iostream>
using namespace std;
int main()
{
char name[20];
char* ptr1,*ptr2;
cout << "Enter a name -> ";
cin >> name;
cout << "Output : ";
for (ptr1 = &name[0]; ptr1 != '\0'; ptr1++)
{
for (ptr2 = ptr1; ptr2 != '\0'; ptr2++)
cout << *ptr2;
cout << ' ';
}
cout << endl;
system("pause");
return 0;
}
Last edited on
This:
for (ptr1 = &name[0]; ptr1 != '\0'; ptr1++)
should probably be:
for (ptr1 = &name[0]; *ptr1 != '\0'; ptr1++)
And probably the same with ptr2.
Erm... could you please not use system(), and rather use cin.ignore(); cin.ignore();
? It's considerably better form.
-Albatross