세그멘테이션 오류가 나요ㅜㅜㅜ도와주세요..
이루리
질문 제목 : 질문 요약 :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같은 문자열 조작 함수들을 사용하셧으면, 버퍼오버플로우등이 일어나는지살펴보시시기 바랍니다. 포인터를 사용하셧으면 포인터 부분도 유심히 보시기 바래요.
-
너만
네.... 딱 저기 써놓은 부분까지는 출력이되던데요;;
안되나요? 우분투랑 시그윈했는데 되던데...ㅜㅜㅜ
도와주세요ㅠㅠㅠㅠㅠㅠ -
덕이
컴파일이 잘 되요?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |