수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

소스 오류질문드립니다.

에드문드

2023.04.01

#includestdio.h
#includestdlib.h
typedef struct process{
char name[20]; //프로세스 이름
int arrive; //도착시간
int turnaround;
int waiting;
int running; //실행시간
int run;
int processNo;

};
struct process tmp;
int n=0;
int total=0;
int total2=0;
int quantum;
struct process *list;
struct process *queue;
void Menu()
{
printf(Main Menu\n);
printf(1) View Process information\n);
printf(2) First Come First Service (FCFS)\n);
printf(3) Shortest Job First (SJF)\n);
printf(4) Shortest Remaining Job First (SRT)\n);
printf(5) Round Robin (RR)\n);
printf(6) Exit\n);
}
void sort(process* queue=(process*)malloc(sizeof(process)*n)){
int a, b;
for (a=0; an-1; a++)
for (b=a+1; bn; b++)
if (queue[a].arrive queue[b].arrive){
tmp=queue[a];
queue[a]=queue[b];
queue[b]=tmp;
}
}
void View_Process_information()
{
int i=0;
FILE *fp=fopen(Process.txt,rt);

while(in)
{
fscanf(fp,%s\t%d\t%d,list[i].name, list[i].running, list[i].arrive);
printf(%s\t%d\t%d\n,list[i].name, list[i].running, list[i].arrive);
i++;
}
fclose(fp);

}
void tt(int pc)
{
int i;
for (i=0; ipc; i++)
total+=list[i].running;
total2=total;
}

void func_print(process* queue=(process*)malloc(sizeof(process)*n), int* gantt=(int*)malloc(sizeof(int)*total)){
int i=0, turnaround=0, waiting=0;
for (i=0,turnaround=0,waiting=0; in; i++){
turnaround+=queue[i].turnaround;
waiting+=queue[i].waiting;
}
printf(\n 1. Gantt Chart\n);
printf ( );
for (i=0; itotal; i++)
printf (%d,gantt[i]);
printf(\n 2. Average turnaround time : %d/%d = %f, turnaround,n,(float)turnaround/n);
printf(\n 3. Average waiting time : %d/%d = %f, waiting,n,(float)waiting/n);
printf(\n\n);
turnaround=0;
waiting=0;
total=total2;
free(gantt);
}//Function print

void FCFS(process* queue=(process*)malloc(sizeof(process)*n)){//FCFS
int* gantt=(int*)malloc(sizeof(int)*total);
int a, i=0;
for (i=0; in; i++)
queue[i]=list[i];
sort(queue);
i=0;
for (a=0; an; a++){
while ( queue[a].running 0 ){
gantt[i]=queue[a].processNo;
queue[a].running--;
i++;
queue[a].turnaround = i-queue[a].arrive;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
}
func_print(queue,gantt);
}

void SJF(process* queue=(process*)malloc(sizeof(process)*n)){//SJF
int* gantt=(int*)malloc(sizeof(int)*total);
int b, i=0, a=0;

for (i=0; in; i++)
queue[i]=list[i];
sort(queue);
i=0;
while (an){
while ( queue[a].running 0 ){
gantt[i]=queue[a].processNo;
queue[a].running--;
i++;
queue[a].turnaround = i-queue[a].arrive;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
a++;
for (b=a+1; bn; b++)
if (queue[b].arrive = i && queue[a].running queue[b].running){
tmp=queue[b];
queue[b]=queue[a];
queue[a]=tmp;
}
}
func_print(queue,gantt);
}

void SRT(process* queue=(process*)malloc(sizeof(process)*n)){//SRT
int* gantt=(int*)malloc(sizeof(int)*total);
int b, i=0, a=0;

for (i=0; in; i++)
queue[i]=list[i];
sort(queue);
i=0;

while (an){
while ( queue[a].running 0 ){
for (b=a+1; bn; b++)
if (queue[b].arrive = i && queue[a].running queue[b].running){
tmp=queue[b];
queue[b]=queue[a];
queue[a]=tmp;
} // 현재 도착한 프로세스중 실행시간이 짧을경우 실행되고 있는 프로세스와 교체
gantt[i]=queue[a].processNo;
queue[a].running--;
i++;
queue[a].turnaround = i-queue[a].arrive;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
a++;
}
func_print(queue,gantt);

}

void RR(process* queue=(process*)malloc(sizeof(process)*n)){//RR
int* gantt=(int*)malloc(sizeof(int)*total);
int b, a =0, i=0;
int next=0;
int quantum = 0;
printf(quantum 입력: );
scanf(%d,&quantum);
for (i=0; in; i++)
queue[i]=list[i];
sort(queue);

i =0;

while (itotal){
a = next%n;
if ( queue[a].arrive = i){
for (b=0; bquantum && queue[a].running0; b++){
gantt[i]=queue[a].processNo;
queue[a].running--;
i++;
queue[a].turnaround = i-queue[a].arrive;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
}

next++;
}
func_print(queue,gantt);
}

void Scheduler_Selection()
{
int number;
tt(n);
scanf(%d,&number);
// 선택한 scheduling Algorithmlgorithms 함수를 호출한다.
switch(number)
{
case 1: View_Process_information();
break;
case 2: FCFS(queue);
break;
case 3: SJF(queue);
break;
case 4: SRT(queue);
break;
case 5: RR(queue);
break;
case 6: exit(1);
break;
}
Menu();
Scheduler_Selection();
}

void main(){
int i;
FILE *Pit=fopen(Process.txt,wt);
printf(Process 개수 입력: );
scanf(%d,&n);
struct process * list=(struct process*)malloc(sizeof(struct process)*n);
struct process * queue=(struct process*)malloc(sizeof(struct process)*n);
printf(Process_name, CPU_time, Arrival_time 입력: \n);
for (i=0; in; i++){
list[i].processNo=i+1;
scanf(%s %d %d,&list[i].name,&list[i].running, &list[i].arrive);
fprintf(Pit,%s\t%d\t%d\n,list[i].name, list[i].running, list[i].arrive);
list[i].run = list[i].running;
}
Menu();
Scheduler_Selection();

fclose(Pit);
}

원래 c++소스인데 c로 돌리려고하니 에러가 뜹니다. 왜 에러뜨나요?

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

  • 콩알눈

    이런 질문을 올릴 때에는 에러메시지를 함께 올려야 빠른 답변을 받을 수 있습니다.
    우선
    void main() {
    을
    int main(void) {
    로 바꾸고
    main 함수가 끝나기 전에 return 0;을 넣어주세요.

번호 제 목 글쓴이 날짜
2700400 원넓이를 계산이요 ㅜㅜ 천칭자리 2025-07-04
2700368 if에 관해서 질문이요... Orange 2025-07-04
2700339 이거 결과값이 왜이런건지.. (4) 그댸와나 2025-07-04
2700313 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) 크나 2025-07-03
2700287 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) 아련나래 2025-07-03
2700264 문자와 숫자 동시에 입력??? 글고운 2025-07-03
2700236 txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) 미국녀 2025-07-03
2700211 전위 연산자 (2) 어른처럼 2025-07-02
2700183 C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; 피스케스 2025-07-02
2700150 꼭좀 도와주세요ㅠㅠㅠ 호습다 2025-07-02
2700095 연산문제...질문... 오빤테앵겨 2025-07-01
2700070 while문 , 3의배수 출력하는 프로그램좀 짜주세욤. 횃불 2025-07-01
2700041 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? 헛장사 2025-07-01
2700012 배열// (1) 전갈자리 2025-07-01
2699895 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) 선아 2025-06-30
2699842 질문을 너무 많이 하네여.....죄송.... (2) 해님꽃 2025-06-29
2699816 오류 질문입니다.. (1) 해비치 2025-06-29
2699763 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) 미라 2025-06-28
2699555 c언어 다항식을 입력을 했는데 왜 출력이 안될까요? 피스케스 2025-06-27
2699528 C언어 포인터연산 질문입니다. (3) 안녕나야 2025-06-26
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com