#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char firstname[] = "Alfred";
char middlename [] = "E";
char lastname[] = "Neuman";
char fullname [80];
int offset=0;
strcpy(fullname,firstname);
offset = strlen(firstname);
strcpy(fullname+offset," ");
offset +=1;
strcpy(fullname+offset,middlename);
offset += strlen(middlename);
strcpy(fullname+offset," . ");
offset +=2;
strcpy(fullname+offset,lastame);
cout << firstname << "." << middlename << "." << lastname << endl;
cout << "Fullname:" << fullname << endl;
return 0;
}
Why is offset needed in this and why is the off set added by 1 and 2, when we are dealing with text. I cannot seem to grasp strings and Arrays, anyone mind helping?
That’s because you’re using the wrong tools.
The offset is used to track the current position of the string in the array so that you can
strcpythe new argument into the right place.