Why does this code give memory violation?
#include <stdio.h>
int main(void)
{
char string[80];
char substring[80];
char temp[256];
//int pos = 0;
temp[0] = '\0';
int loc, i, j;
printf("Enter string: ");
scanf("%s",&string);
printf("Enter substring: ");
scanf("%s",&substring);
printf("Enter position: ");
scanf("%d",&loc);
j=0;
for(i=0; i < loc-1; i++)
temp[j++] = string[i];
for(i=0; substring[i] != '\0'; i++)
temp[j++] = substring[i];
for(i=loc-1; string[i] != '\0'; i++)
temp[j++] = string[i];
temp[j] = '\0';
printf("%s",temp);
return 0;
}