Hi, could someone tell me where I went wrong in this source code.
I got an application error , 'the instruction at "oXoo40.." referenced memory at "0xcc.." the memory could not be written.
I compiled this using Visual C++
/*function InsertString
Takes in :
string A & string B & int C
Operation:
insert B into A at Cth Position
e.g. InsertString("aaaaa","bb",2) will return string "aabbbaaa"*/
#include<stdio.h>
#include<string.h>
char *InsertString(char *A, char *B, int C);
void main()
{
char *A;
char *B;
int x;
printf("\nKey in string1: ");
scanf("%s",A);
printf("\nKey in string2: ");
scanf("%s",B);
printf("\nKey in Position: ");
scanf("%d",&x);
printf("Result of insertion : \n");
printf("%s",InsertString(A,B,x));
}
char *InsertString(char *A, char *B, int C)
{
char *temp;
char *ptr;
if((C>strlen(A))||(C<0))
return NULL;
else
{
ptr=A+C;
strcpy(temp,B);
strcat(temp,ptr);
ptr='\0';
strcat(A,temp);
}
return strcat(A,temp);
}
Thanks
Jacquiline