Floating point exception (core dumped)고수님들 도와주시면 감사하겠습니다.
글쓴이: p12172 / 작성시간: 수, 2018/06/06 - 6:10오후
Floating point exception (core dumped)
이렇게 뜨고는 자꾸 종료됩니다 ㅠㅠ 도대체 어떻게 해야할까요? 코드는 아래에 올려봅니다. 보여드리기 민망한 실력이라 죄송합니다. ㅠㅠ 부디 이 어린양을 바른길로 인도하소서 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <time.h> 5 #include <termios.h> 6 7 int getch(void) 8 { 9 int ch; 10 struct termios buf, save; 11 tcgetattr(0, &save); 12 buf = save; 13 buf.c_lflag &= ~(ICANON | ECHO); 14 buf.c_cc[VMIN] = 1; 15 buf.c_cc[VTIME] = 0; 16 tcsetattr(0, TCSAFLUSH, &buf); 17 ch = getchar(); 18 tcsetattr(0, TCSAFLUSH, &save); 19 return ch; 20 } 21 22 int main(void) 23 { 24 srand(time(NULL)); 25 26 unsigned S; 27 28 int Exit=1; 29 char input[100]={0}, Input; 30 int record[5], again, letters, n, x, total=0, acc=0; 31 int progress=0, best_type, current_type, comparing_type, accurateness; 32 char d='%', origin; 33 clock_t start_clock, end_clock, diff_clock, ex_time; 34 35 char sentence[30][100]= 36 { 37 "To be or not to be that is a question.\n", 38 "I believe I can fly.\n", 39 "Cause, We will, We will rock you.\n", 40 "Fly me to the moon, and let me play among the stars.\n", 41 "God, Forgive us.\n", 42 "I was born to love you.\n", 43 "Can you feel the love tonight?\n", 44 "I hear Jerusalem bells a ringing.\n", 45 "Let's get out tonight.\n", 46 "When you're gone, The pieces of my heart are missing you.\n", 47 "Forgive me girl. Lady won't you save me. My heart belongs to you.\n", 48 "Maybe I'm defective or maybe I'm dumb.\n", 49 "If this is love, then love is easy.\n", 50 "I'm at a payphone trying to call home, all of my change I spent on you\n", 51 "Sugar! Yes, please. Won't you come and put it down on me.\n", 52 "Honesty, It such a lonely word.\n", 53 "But I wonder where were you. When I was at my worst, Down on my knees.\n", 54 "All the moves like Jagger. I've got the moves like Jagger.\n", 55 "So I cross my heart and I hope to die.\n", 56 "Got me so high and then she dropped me. But she got me\n", 57 "All I want for Christmas is you.\n", 58 "Won't you marry me if I could be a rich boy?\n", 59 "Billie Jean is not my lover, She's just a girl who claim that I am the one\n", 60 "Oh baby give me one more chance show that I love you.\n", 61 "ABC easy as 123. Or simple as Do re mi, ABC, 123, baby, you and me girl.\n", 62 "Take this sinking boat and point it home, We've still got time.\n", 63 "Let it go, Let it go. Can't hold it back anymore.\n", 64 "Never mind, I'll find someone like you.\n", 65 "We could have had it all. Rolling in the deep.\n", 66 "Listen, I am alone at a crossroads. I'm not at home in my own home.\n" 67 }; 68 69 70 start_clock=clock(); 71 72 while(Exit){ 73 for(again=0; again<=5; again++)//Body of Mode. 74 { 75 76 S=rand() % 30;//Save the value randomly, from 0 to 29. 77 78 for(n=0;n<100;n++) 79 { 80 81 if(again==0)//when the typingspeed are not defined. 82 { 83 best_type=0; 84 current_type=0; 85 } 86 else//when the typingspeed are defined, then comparing the speed. 87 { 88 comparing_type=best_type; 89 if(comparing_type>=current_type) 90 best_type=comparing_type; 91 else 92 best_type=current_type; 93 } 94 95 if(acc==0)//shut down the probability of overflow. 96 accurateness=0; 97 else 98 accurateness=acc/total;//find the accurateness 99 100 if(again==0)//when the typingspeed are not defined. 101 { 102 best_type=0; 103 current_type=0; 104 } 105 106 system("clear"); 107 printf(">> 영문 타자 연습 프로그램 : 짧은 글 연습<<\n"); 108 printf("진행도 : %d%c 현재타수 : %d 최고타수 : %d 정확도 : %d%c\n", progress*20, d, current_type, best_type, accurateness, d); 109 for(x=0; x<100; x++) 110 { 111 printf("%c", sentence[S][x]); //print letters. 112 } 113 for(int y=0; y<100; y++)//print inputed letters by user. 114 { 115 printf("%c", input[y]); 116 } 117 118 Input=getch(); 119 120 end_clock=clock(); 121 diff_clock = end_clock - start_clock; 122 ex_time = diff_clock / CLOCKS_PER_SEC; 123 current_type = acc / ex_time; 124 125 input[n]=Input; 126 127 if(Input=='\x7f')//when user presses backspace. 128 { 129 if(input[n-1]==sentence[S][n-1]) 130 { 131 acc--; 132 total--; 133 } 134 else 135 total--; 136 137 input[n-1]=0; 138 n--; 139 n--; 140 continue; 141 } 142 143 if(Input=='\n')//when user presses enter, before the complete practice. 144 break; 145 } 146 147 148 progress++; 149 } 150 151 printf("짦은 글 연습이 끝났습니다. Enter를 눌러 메뉴로 나가십시오."); 152 Input=getch(); 153 154 if(Input=='\n') 155 Exit=0; 156 157 sleep(1); 158 } 159 return 0; 160 }
Forums:
코드를 올리실때 행번호는 지우셔야 답하려는 사람들이
코드를 올리실때 행번호는 지우셔야 답하려는 사람들이 바로 복사해서 해볼수 있겠지요.
current_type = acc / ex_time 에서 0으로 나누다가 발생하네요.
좋은 하루 되세요!
아 그렇군요...
아 제가 이 사이트를 처음 이용해봐서요 여러므로 감사드립니다. 참 친절하시네요
댓글 달기