replace 함수를 사용하랍니다.ㅠ급합니다ㅠ
유진공주
질문 제목 : 기본소스에서 replace함수를 사용하여 출력값이 그대로 똑같이 나오게 하라는데...모르겠어요ㅠ질문 내용 :
#include stdio.h
#include stdlib.h
#define max_list_size 100 // 배열의 최대 크기
typedef int element;
typedef struct
{
int list[max_list_size]; // 배열 정의
int length; // 현재 배열에 저장된 자료들의 개수
} arraylisttype;
// 오류 처리 함수
void error(char *message)
{
fprintf(stderr, %s\n, message);
exit(1);
}
// 리스트 초기화
void init(arraylisttype *l)
{
l - length = 0;
}
// 리스트가 비어 있으면 1을 반환
// 그렇지 않으면 0을 반환
int is_empty(arraylisttype *l)
{
return l - length == 0;
}
// 리스트가 가득 차 있으면 1을 반환
// 그렇지 않으면 0을 반환
int is_full(arraylisttype *l)
{
return l - length == max_list_size;
}
// 리스트 출력
void display(arraylisttype *l)
{
int i;
for(i=0; il-length; i++)
printf(%d\n, l - list[i]);
}
// position : 삽입하고자 하는 위치
// item : 삽입하고자 하는 자료
void add(arraylisttype *l, int position, element item)
{
if(!is_full(l) && (position = 0) && (position = l - length))
{
int i;
for(i=(l - length-1); i=position; i--)
l-list[i+1] = l-list[i];
l-list[position] = item;
l-length++;
}
}
// position : 삭제하고자 하는 위치
// 반환 값 : 삭제되는 자료
element delete(arraylisttype *l, int position)
{
int i;
element item;
if(position 0 || position = l - length)
error(위치 오류);
item = l-list[position];
for(i=position; 1(l - length-1); i++)
l-list[i] = l-list[i+1];
l-length--;
return item;
}
//
main()
{
arraylisttype list1;
arraylisttype *plist;
// listtype을 정적으로 생성하고 listtype을 가리키는
// 포인터를 함수의 매개 변수로 전달한다.
init(&list1);
add(&list1, 0, 10);
add(&list1, 0, 20);
add(&list1, 0, 30);
add(&list1, 0, 40);
add(&list1, 0, 50);
display(&list1);
// listtype을 동적으로 생성하고 listtype을 가리키는
// 포인터를 함수의 매개 변수로 전달한다.
plist = (arraylisttype *)malloc(sizeof(arraylisttype));
init(plist);
add(plist, 0, 10);
add(plist, 0, 30);
add(plist, 0, 20);
add(plist, 0, 10);
display(plist);
free(plist);
}
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752115 | c언어 이상한질문 (4) | 모드니 | 2026-10-21 |
| 2752085 | 문자열을 랜덤하게 출력해서 대체,삽입,삭제 횟수를 각가 표시하고 그걸 표 형태로 출력 | 슬아s | 2026-10-20 |
| 2752056 | 포인터 && 배열 질문요~ (2) | 해찬나래 | 2026-10-20 |
| 2752031 | x^n 구하는 코드 짜봤는데 값이 틀려요 ㅠㅠ | 세실 | 2026-10-20 |
| 2752000 | 나 정말 미치겠어요..ㅠㅜ (4) | 다이 | 2026-10-20 |
| 2751978 | 문자열 질문이요.. | 초시계 | 2026-10-19 |
| 2751945 | 숫자 맞추는 프로그램이요 ㅠㅠ (1) | 동은 | 2026-10-19 |
| 2751917 | C언어 이중 연결 관련 질문합니다. | 유우 | 2026-10-19 |
| 2751888 | return의 정확한 의미좀 알려주세요 (3) | 올해1살 | 2026-10-19 |
| 2751857 | 포인터 배열 (2) | 터큰 | 2026-10-18 |
| 2751831 | 연산자? 질문입니다 (2) | 진주 | 2026-10-18 |
| 2751800 | C언어 기초질문입니다.. (3) | 핫블랙 | 2026-10-18 |
| 2751739 | 파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요. (2) | 얼 | 2026-10-17 |
| 2751715 | unresolved external symbol 에러... | 이룩 | 2026-10-17 |
| 2751686 | 변수 설정에 관한 질문입니다. | 꽃달 | 2026-10-17 |
| 2751655 | 자료구조 연습문제 | 한무릎 | 2026-10-17 |
| 2751631 | gets 함수 질문이요. (4) | 해늘 | 2026-10-16 |
| 2751553 | 퀵정렬 소스인데 주석좀 달아주세요 (1) | 싴흐한세여니 | 2026-10-16 |
| 2751528 | 저기 이거하는법좀 질문.. (2) | 가람슬기 | 2026-10-15 |
| 2751445 | 도저히 풀 수가 없네요.... (2) | 신당 | 2026-10-15 |
