세그멘테이션 오류가 나요ㅜㅜㅜ도와주세요..
이루리
질문 제목 : 질문 요약 :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같은 문자열 조작 함수들을 사용하셧으면, 버퍼오버플로우등이 일어나는지살펴보시시기 바랍니다. 포인터를 사용하셧으면 포인터 부분도 유심히 보시기 바래요.
-
너만
네.... 딱 저기 써놓은 부분까지는 출력이되던데요;;
안되나요? 우분투랑 시그윈했는데 되던데...ㅜㅜㅜ
도와주세요ㅠㅠㅠㅠㅠㅠ -
덕이
컴파일이 잘 되요?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |