Original Post
Hi - The code below will basically copy one char array into another but alas I cannot achieve this as you will see.
#include<iostream>
using namespace std;
// functions prototypes //
void FillDisks(char* ch_ptr1, char* ch_ptr2, char* ch_ptr_A);
void main()
{
char disk[50];
char* ch_ptr_A = disk;
char tempArray1[50], tempArray2[50];
char* ch_ptr1 = tempArray1;
char* ch_ptr2 = tempArray2;
cout << "Enter some data for array1...";
cin >> tempArray1;
cout << "\nEnter some data for array2...";
cin>> tempArray2;
FillDisks(ch_ptr1, ch_ptr2, ch_ptr_A);
// print out array!! //
for(int x=0; x<50; ++x)
{
cout << disk[x];
}
}
// Functions //
void FillDisks(char* ch_ptr1, char* ch_ptr2, char* ch_ptr_A)
{
cout << "\n\n\nthis is in tempArray1 ... " << ch_ptr1;
cout << endl;
cout << "\nlength of tempArray1=" << strlen(ch_ptr1) << "\n\n";
// dereferencing.............
for(int i=0; i<strlen(ch_ptr1); i++)
{
*ch_ptr_A++ = *ch_ptr1++; // this is the culprit line, i think!
}
cout << "\n\n\nthis is in tempArray1 ... " << ch_ptr1;
cout << endl;
cout << "\nlength of tempArray1=" << strlen(ch_ptr1) << "\n\n";
cout << "\n\n\n\n";
}
1. ask user for data ; only tempArray1 is being used here... 2. goto to func and print out contents of array and the length of string therein 3. copy tempArray1 to disk[]; 4. print out contents of array and the length of string therein ; again. 5. return and print out contents of newly filled array; disk[] problem is.... it only copies part of the string and I dont know why!!