오류를 잡아주세요
에다
질문 제목 :
오류를 잡아주세요!질문 요약 :
돌리게 되면 s2이 corrupted 된다고 뜹니다. 이유를 모르겠네요 ㅠㅠ질문 내용 : #includestdio.h
#includestring.hint strninsert(char *s1, char *s2, int pos, int n);int main()
{
char s1, s2;
char *ins;
int pos, n;
int result; gets(&s1);
gets(&s2);
scanf(%d %d, &pos, &n);
}int strninsert(char *s1, char *s2, int pos, int n)
{
int i, j, k;
char *ins;
int temp1, temp2, temp3; if(pos strlen(s1) && pos0)
return 0;
else
{
for(i = 0;i pos;i++)
ins[i] = s1[i];
temp1 = i; for(j = 0;j n-1; j++)
ins[j+temp1] = s2[j];
temp2 = j;
temp3 = temp1+temp2; for(k = 0;k strlen(s1) - pos; k++)
ins[k + temp3] = s1[k+temp1];
printf(%s,ins); return 1;
}
}
hello, world, 3, 4 를 입력하면 helworllo처럼 3이 떠야합니다.
3이 커서위치 5가 나중에 입력한 단어 들어가는 갯수고요.
뭐가 잘못된건지 모르겠네요 ㅠㅠ
-
하예라 2023-08-24
동적할당이요? 조금만 더 설명해주시면 안될까요..?
-
모드니 2023-08-24
ins로 동적할당한 배열의 주소를 받은 뒤 사용해보세요.