세그멘테이션 오류가 나요ㅜㅜㅜ도와주세요..
이루리
질문 제목 : 질문 요약 :cygwin이나 ubuntu에서 돌렸구요.
컴파일은 잘 되는데
아래 표시된 부분 딱 출력하구 세그멘테이션 오류라고 떠요...
왜그럴까요? %s 이부분을 &해서 그렇다해서
&도 빼고했는데......왜그런지 잘모르겠어요ㅠㅠ 알려주세여ㅜㅜ질문 내용 :
#includestdio.h
#includestdlib.h
struct process{
char name[10];
int arrive;
int running;
int run;
int order;
int processNo;
int turnaround;
int waiting;
};
struct process* queue;
struct process* list;
int n=0;
int total=0;
int quantum;
struct process tmp;
//int* gantt = (int*)malloc(sizeof(int)*total);
void func_print(){
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);
}//Function print
void FCFS(){//FCFS
int* gantt=(int*)malloc(sizeof(int)*total);
int a, 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(){//SJF
int* gantt=(int*)malloc(sizeof(int)*total);
int b, i=0, a=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(){//SRT
int* gantt=(int*)malloc(sizeof(int)*total);
int b, i=0, a=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(){//RR
int* gantt=(int*)malloc(sizeof(int)*total);
int b, a, i=0;
int next=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 Priority(){//priority sceduling
int* gantt=(int*)malloc(sizeof(int)*total);
int order, next=0;
int a, b, i=0;
while (itotal){
for (a=0; an; a++){
for (b=0, order=10000; bn; b++)
if ( queue[b].arrive = i && queue[b].order order )
order=queue[b].order;
if (queue[a].order = order && 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;
}
if (queue[a].ordern+1)
queue[a].order++;
}
}
}
func_print(queue,gantt);
}
void func_sort(){
int a, b;
for (a=0; an-1; a++)
for (b=a+1; bn; b++)
if (queue[a].arrive queue[b].ueue[b].arrive){
tmp=queue[a];
queue[a]=queue[b];
queue[b]=tmp;
}
}
int main(){
int i;
printf( 몇개의 프로세스를 입력 하시겠습니까? : );
scanf(%d,&n);
struct process* list = (struct process*)malloc(sizeof(struct process)*n);
struct process* queue = (struct process*)malloc(sizeof(struct process)*n);
//process* list=(process*)malloc(sizeof(process)*n);
//process* queue=(process*)malloc(sizeof(process)*n);
printf( 프로세스 이름, 도착시간, 실행시간, 우선순위를 순서대로 입력하되\n);
printf( 각각 한칸씩 띄워주세요. 프로세스 이름은 10자이내, 이름사이에 띄워쓰기\n);
printf( 할수 없습니다.( ex name 1 10 3 )\n);
for (i=0; in; i++){
list[i].processNo=i+1;
printf( %d 번째 프로세스 정보 입력 : ,list[i].processNo);
scanf(%s %d %d %d,
list[i].name,&list[i].arrive,&list[i].running,&list[i].order);
list[i].run = list[i].running;
}
printf( Time Quantum을 입력하세요 : );
scanf(%d, &quantum);
printf(\n 다음이 프로세스 넘버와 프로세스 이름입니다.\n);
printf( 간트차트는 프로세스 넘버가 출력됩니다.\n);
for (i=0; in; i++)
printf( %d : %s ,list[i].processNo, list[i].name);
for (i=0; in; i++)
total+=list[i].running;
printf(\n******* First-Come-First-Served *******\n);//FCFS
////////////////// 여기까지만 출력됨../////////////////////////////////
///////////////////////////////////////////////////////////////////
//////////////// 여기 아래서부터 에러가 남.../////////////////////////
for (i=0; in; i++)
queue[i]=list[i];
func_sort(queue);
FCFS(queue);
printf(\n********** Shortest Job First **********\n); //SJF
for (i=0; in; i++)
queue[i]=list[i];
func_sort(queue);
SJF(queue);
printf(\n***** Shortest Remaining Time Next *****\n); //SRT
for (i=0; in; i++)
queue[i]=list[i];
func_sort(queue);
SRT(queue);
printf(\n************* Round - Robin *************\n); //RR
for (i=0; in; i++)
queue[i]=list[i];
func_sort(queue);
RR(queue);
printf(\n********** Priority Scheduling **********\n); //Priority
for (i=0; in; i++)
queue[i]=list[i];
func_sort(queue);
Priority(queue);
return 0;
}
-
권애교
ㅠㅠ어떻게해야할까요??
-
차나
답변 오류였기 때문에 삭제합니다.
-
매1혹
세그멘테이션 오류는 대부분 메모리 잘못 건드렷을때 납니다. strcpy같은 문자열 조작 함수들을 사용하셧으면, 버퍼오버플로우등이 일어나는지살펴보시시기 바랍니다. 포인터를 사용하셧으면 포인터 부분도 유심히 보시기 바래요.
-
너만
네.... 딱 저기 써놓은 부분까지는 출력이되던데요;;
안되나요? 우분투랑 시그윈했는데 되던데...ㅜㅜㅜ
도와주세요ㅠㅠㅠㅠㅠㅠ -
덕이
컴파일이 잘 되요?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
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 |