remember ronin showed me this code last week ... basically inserting string 2 into string 1, user decides where to make the string insertion.
Code:
#include <iostream.h>
int main(void)
{
char user1[80];
char user2[80];
char temp[256];
temp[0] = '\0';
int loc, i, j;
cout << "Enter string1: ";
cin.getline(user1, 80);
cout << "Enter string2: ";
cin.getline(user2, 80);
cout << "Enter loc where to place string 2 into string 1: ";
cin >> loc;
j=0;
for(i=0; i < loc-1; i++)
temp[j++] = user1[i];
for(i=0; user2[i] != '\0'; i++)
temp[j++] = user2[i];
for(i=loc-1; user1[i] != '\0'; i++)
temp[j++] = user1[i];
temp[j] = '\0';
cout << endl << temp << endl;
return 0;
}
this of course works perfectly fine
but when it's my turn to incorporate stuff into it, obviously the whole thing crashed !
I'm just trying to use that to work with 2 dimensional arrays, like so....
Code:
#include<iostream.h>
int main()
{
const int MAX=3;
char array1[MAX][81];
char array2[MAX][81];
char temp[MAX][81];
int location,j;
int i=0;
cout<<"enter string 1"<<endl;
cin.getline(array1[i],80);
cout<<"enter string 2"<<endl;
cin.getline(array2[i], 80);
cout<<"location in string1 to insert string2 ?: ";
cin>>location;
j=0;
for(i=0; i<location-1; i++)
temp[0][j++]=array1[0][i];
// element [0] because I'm trying to copy line 1 of array1 into
// line 1 of temp.
//for(i=0; array2[i]!='\0'; i++)
// temp[0][i++]=array2[0][i];
//for(i=location-1; array1[i]!='\0'; i++)
// temp[0][j++] = array1[0][i];
// the last 2 for loops are commented out, coz they crashed my
// whole comp. !
cout<<temp[i];
return 0;
}