세그멘테이션 오류가 나요ㅜㅜㅜ도와주세요..
이루리
질문 제목 : 질문 요약 :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같은 문자열 조작 함수들을 사용하셧으면, 버퍼오버플로우등이 일어나는지살펴보시시기 바랍니다. 포인터를 사용하셧으면 포인터 부분도 유심히 보시기 바래요.
-
너만
네.... 딱 저기 써놓은 부분까지는 출력이되던데요;;
안되나요? 우분투랑 시그윈했는데 되던데...ㅜㅜㅜ
도와주세요ㅠㅠㅠㅠㅠㅠ -
덕이
컴파일이 잘 되요?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |
2698616 | 다른 함수로 안넘어갑니다..;;; | 도1도캣 | 2025-06-18 |
2698587 | 배열하다 막혀서... (3) | WhiteCat | 2025-06-18 |
2698559 | 문자열을 비우는방법 (2) | 하늘 | 2025-06-18 |
2698528 | 착하고 친절한 선생씌구해염~ㅋㅋ (4) | 옆집언니야 | 2025-06-17 |
2698502 | 자료구조 큐 | 캔서 | 2025-06-17 |
2698477 | 실행화면 배경문의요 | 선아 | 2025-06-17 |
2698430 | 변수의 값이 저장이 않되네요;; (4) | 피네 | 2025-06-16 |