기초적인 질문 드립니다;;
시나브로
#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);
}
여기서 실행을 하면 값을 입력한뒤 결과화면이 바로 종료가 되는데
어떤걸 고쳐야될지 몰라서 질문드립니다;;