기초적인 질문 드립니다;;
별솔
#include stdio.h
typedef struct
{
int UseageSpace; // 사용 공간
int RemainSpace; // 남은 공간
}Memory;
void FirstFit(Memory m[], int n, int RequestSpace)
{
int i=0;
while(i n)
{
if(m[i].RemainSpace = RequestSpace)
{
m[i].UseageSpace += RequestSpace;
m[i].RemainSpace -= RequestSpace;
printf(%d번째 공간에 배치하였습니다.\n, i+1);
return;
}
i++;
}
printf(요청작업을 공간에 배치할수 없습니다.\n);
}
void BestFit(Memory m[], int n, int RequestSpace)
{
int i;
int BestIndex = -1;
for(i = 0; i n; i++)
{
if(BestIndex == -1)
{
if(m[i].RemainSpace = RequestSpace)
BestIndex = i;
}
else
{
if(m[i].RemainSpace = RequestSpace)
{
if(m[i].RemainSpace m[BestIndex].RemainSpace)
BestIndex = i;
}
}
}
if(BestIndex == -1)
printf(요청작업을 공간에 배치할수 없습니다.\n);
else
{
m[BestIndex].UseageSpace += RequestSpace;
m[BestIndex].RemainSpace -= RequestSpace;
printf(%d번째 공간에 배치하였습니다.\n, BestIndex+1);
}
}
void WorstFit(Memory m[], int n, int RequestSpace)
{
int i;
int WorstIndex = 0;
for(i = 1; i n; i++)
{
if(m[i].RemainSpace m[WorstIndex].RemainSpace)
WorstIndex = i;
}
if(m[WorstIndex].RemainSpace = RequestSpace)
{
m[WorstIndex].UseageSpace += RequestSpace;
m[WorstIndex].RemainSpace -= RequestSpace;
printf(%d번째 공간에 배치하였습니다.\n, WorstIndex+1);
}
else
printf(요청작업을 공간에 배치할수 없습니다.\n);
}
void Print(Memory m[], int n)
{
int i ;
for(i = 0; i n; i++)
{
printf(%d번째 : %2dK 공백 %2dK 사용중\n,i+1, m[i].RemainSpace, m[i].UseageSpace);
}
}
void main()
{
int RequestSpace;
Memory m[7] =
{
{ 0, 17 },
{ 10, 0 },
{ 0, 7 },
{ 4, 0 },
{ 0, 15 },
{ 20, 0 },
{ 0, 50 },
}; // 7개의 구역으로 나누었습니다.
Print(m, 7);
printf(기억장치 공간 입력 : );
scanf(%d, &RequestSpace);
FirstFit(m, 7, RequestSpace);
//WorstFit(m, 7, RequestSpace);
//BestFit(m, 7, RequestSpace);
Print(m, 7);
}
여기서 실행을 하면 값을 입력한뒤 결과화면이 바로 종료가 되는데
어떤걸 고쳐야될지 몰라서 질문드립니다;;
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752142 | 더블 포인터 관련 최대최소값 구하기 (2) | 풀잎 | 2026-10-21 |
| 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 |
