Hi,
First of all apologies for a small but screwing mistake in the program! and once again no comments which makes it dfifficult! Wasnt feeling well so posted in a hurry! Here are a few comments and an extra addition in
RED . Thanks a lot for pointing out the mistake.
Code:
#include <stdio.h>
int main() {
char str1[] = "aman";
char str2[20] = "Vini";
char *ptr2 = str2;
char *ptr1 = str1;
int count =0;
int counter =0;
while( '\0' != *ptr2 ){
ptr2++;
count++; // Counting the number of characters in the string here.
}
while( '\0' != *ptr1 ){
*ptr2++ = *ptr1++; // Here we are actually concatenating
// the string.
}
*ptr2 = '\0';
printf("str2 = %s, Length of first string = %d", str2, count); // This will show the
//concatenated string.
ptr2 = str2; // Resetting the pointer
// Now belolw is a very crude way of printing just "Vini" from "Viniaman". Not sure here if
// it serves ur purpose.
while(counter < count){
printf("%c", *ptr2++ );
counter++;
}
return 0;
}
Please let me know if you have any doubts on that.