August 13th, 2013, 10:00 AM
Simulating strcat with pointers
Self explanitory title. What am I doing wrong in the programm?
// simulating strcat with some ****ing pointers
printf("Enter string A: "); gets(strA);
printf("Enter string B: "); gets(strB);
if( *(pA+i)== '\0')
*(pA+i) = *(pB+j);
if( *(pB+j) != '\0' )
*(pB+i) == '\0';
printf("The new string is:\n");
August 13th, 2013, 10:37 AM
Why do you think there's anything wrong with it?
IOW, we cannot read your mind! If you are encountering errors or warnings, then tell us. If you are getting unexpected output, then tell us so and give us the exact input, the exact output you got, and the exact output you expected. Do not give us a vague description with a lot of hand-waving.
We especially need those exact descriptions since your code obviously doesn't even begin to emulate strcat. Adding comments to the code to tell us what each part is supposed to be doing would be an invaluable investment of some minimal time and effort on your part.
And please indent your code!
Last edited by dwise1_aol; August 13th, 2013 at 03:22 PM.
August 13th, 2013, 11:32 AM
Why are you ignoring warnings?
Never ignore warnings!
August 13th, 2013, 11:43 AM
Seriously, what you've written has absolutely nothing to do with concatenating strings together.
Stop and think for a minute how you would do that by hand. Go through the steps with pencil and paper. Then you would have some idea what to code.
Until you do that, no amount of trying to fix your present code would accomplish anything.
Indent your code!
Be specific when you report problems to us! Don't try to force us to read your mind or play guessing games with you!
Do not ignore warnings!