Problema con programa fallo de segmentacion

Imagen de Vinicio Steven
0 puntos

Hola, tengo un proble, fallo de segmentacion me gustaria q revisaran el codigo fuente haber q es:

/*** cmath.c *////

/* Vinicio Flores -- CMATH -- Makes a lot of maths functions.>
Copyright (C) 2011 Vinicio Flores

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see
*/

#include "ncurses.h"
#include "stdlib.h"
#include "string.h"

#include "include/cmath.h"

int main(){

WINDOW *menu;

WINDOW *win[10];

start();

init_pair(BACKCOLOR,COLOR_WHITE,COLOR_BLUE);
init_pair(TITLECOLOR,COLOR_GREEN,COLOR_RED);
init_pair(BACKWIN,COLOR_BLACK,COLOR_WHITE);

env();
title();

register int i;

/* Makes a space of memory for the windows */

for(i = 0; i < 10; i++){

height[i] = 30;
width[i] = 50;
starty[i] = (LINES - height[i]) / 2;
startx[i] = (COLS - width[i]) / 2;
}
menu = cwin(height[0], width[0], starty[0], startx[0]);

while((ch = getch())!=KEY_END){

switch(ch){

case KEY_IC:

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);
break;

case KEY_F(1):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);
break;

case KEY_F(2):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(3):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(4):

dwin(menu);
dwin(win[i]);

win[1] = mmin(height[1], width[1], starty[1] + 4, startx[1] + 15);

break;

case KEY_F(5):

dwin(menu);
dwin(win[i]);
win[2] = cmin(height[2], width[2], starty[2], startx[2]);

break;

case KEY_F(6):

dwin(menu);
dwin(win[i]);
win[3] = mft(height[3],width[3],starty[3],startx[3]);

break;

case KEY_F(7):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(8):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(9):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(10):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(11):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_F(12):

dwin(menu);
menu = cwin(height[0], width[0], starty[0], startx[0]);

break;

case KEY_HOME:

dwin(menu);
dwin(win[i]);

clear();

wrefresh(menu);
wrefresh(win[i]);

break;

}

}

end();
return EXIT_SUCCESS;
}

void start(){

noecho();
initscr();
cbreak();
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);

if(has_colors)
start_color();

else {

printf("This terminal does not support colors.\n");
exit(1);
}

}

void end(){

refresh();
getch();
endwin();

}

void title(){

s cord;

getmaxyx(stdscr, cord.y,cord.x);

const char ctitle[]=" C M A T H ";
mvprintw(0,(cord.x - strlen(ctitle)) / 2, "%s", ctitle);
mvchgat(0,0,-1,A_STANDOUT|A_BOLD,TITLECOLOR,NULL);

}

void env(){

bkgd(COLOR_PAIR(BACKCOLOR));
}

WINDOW *cwin(int height, int width, int starty, int startx){

WINDOW *local_win;

local_win = newwin(height + 2, width, starty, startx);
box(local_win,0,0);

wbkgd(local_win,COLOR_PAIR(BACKWIN));

wattron(local_win,A_BOLD);
mvwprintw(local_win,3,2,"Conversiones temperatura: ---> F1)C - F");
mvwprintw(local_win,4,2," ---> F2)F - C");
mvwprintw(local_win,5,2," ---> F3)F - K");
mvwprintw(local_win,6,2," ---> F3)F - K");

mvwprintw(local_win,8,2,"Conversiones de longitud: ---> F4)Mm - in");
mvwprintw(local_win,9,2," ---> F5)Cm - in");
mvwprintw(local_win,10,2," ---> F6)M - ft");
mvwprintw(local_win,11,2," ---> F7)M - yd");
mvwprintw(local_win,12,2," ---> F8)Km - mil");
mvwprintw(local_win,13,2," ---> F9)in - cm");
mvwprintw(local_win,14,2," ---> F10)Ft - cm");
mvwprintw(local_win,15,2," ---> F11)Yd - m");
mvwprintw(local_win,16,2," ---> F12)mil - km");

mvwprintw(local_win,18,2,"Conversiones de volumen ---> A)Ml - oz.fl");
mvwprintw(local_win,19,2," ---> B)oz.fl - ml");
mvwprintw(local_win,20,2," ---> C)L - qt");
mvwprintw(local_win,21,2," ---> D)m3 - ft3");
mvwprintw(local_win,22,2," ---> E)m3 - yd3");
mvwprintw(local_win,23,2," ---> F)c - ml");
mvwprintw(local_win,24,2," ---> G)C - ml");
mvwprintw(local_win,25,2," ---> H)t - l");
mvwprintw(local_win,26,2," ---> I)gal - l");
mvwprintw(local_win,28,2," ---> IC)Ayuda");

mvwprintw(local_win,29,2, " ---> HOME)Limpiar escritorio");

wattroff(local_win,A_BOLD);

wrefresh(local_win);
return local_win;
}

/* Creates and draws the windows */

WINDOW *mmin(int heighta, int widtha, int startya, int startxa){

WINDOW *local_wina,*sublocal;

local_wina = newwin(heighta, widtha, startya, startxa);
box(local_wina,0,0);

init_pair(BORDER,COLOR_RED,COLOR_RED);

sublocal = subwin(local_wina,heighta,widtha,startya,startxa);

wbkgd(sublocal,COLOR_PAIR(BACKWIN));

const char string_mm[]="Milimetros: ";

mvwprintw(sublocal, 3,2,"%s", string_mm);
mvwscanw(sublocal,3,strlen(string_mm) + 2, "%f", &medidas.mm);

medidas.in = medidas.mm * 0.04;

const char equ[]="Equivalente en pulgadas: ";

wattron(sublocal, A_BOLD);
mvwprintw(sublocal, 6,2,"%s", equ);
wattroff(sublocal, A_BOLD);

mvwprintw(sublocal, 6,strlen(equ) + 2,"%f", medidas.in);

wrefresh(local_wina);
return local_wina;
}

WINDOW *cmin(int heightb, int widthb, int startyb, int startxb){

WINDOW *local_winb,*sub;

local_winb = newwin(heightb, widthb, startyb + 3, startxb - 30);
box(local_winb,0,0);

wbkgd(local_winb,COLOR_PAIR(BACKWIN));

sub = subwin(local_winb,heightb,widthb,startyb + 3,startxb - 30);

const char string_cm[]="Centimetros: ";

mvwprintw(sub, 3,2,"%s", string_cm);
mvwscanw(sub,3,strlen(string_cm) + 2, "%f", &medidas.cm);

medidas.in = medidas.cm * 0.39;

const char equ[]="Equivalente en pulgadas: ";

wattron(sub, A_BOLD);
mvwprintw(sub, 6,2,"%s", equ);
wattroff(sub, A_BOLD);

mvwprintw(sub, 6,strlen(equ) + 2,"%f", medidas.in);

wrefresh(local_winb);
return local_winb;

}

WINDOW *mft(int heightc, int widthc, int startyc, int startxc){

WINDOW *local_winc,*subc;

local_winc = newwin(heightc, widthc, startyc + 9, startxc - 40);
box(local_winc,0,0);

wbkgd(local_winc,COLOR_PAIR(BACKWIN));

subc = subwin(local_winc,heightc,widthc,startyc + 9,startxc - 40);

const char string_m[]="Metros: ";

mvwprintw(subc, 3,2,"%s", string_m);
mvwscanw(subc,3,strlen(string_m) + 2, "%f", &medidas.m);

medidas.ft = medidas.m * 3.28;

const char equ[]="Equivalente en pies: ";

wattron(subc, A_BOLD);
mvwprintw(subc, 6,2,"%s", equ);
wattroff(subc, A_BOLD);

mvwprintw(subc, 6,strlen(equ) + 2,"%f", medidas.ft);

wrefresh(local_winc);
return local_winc;

}

WINDOW *myd(int heightd, int widthd, int startyd, int startxd){

WINDOW *local_wind;

local_wind = newwin(heightd, widthd, startyd, startxd);
box(local_wind,0,0);

wbkgd(local_wind,COLOR_PAIR(BACKWIN));

wrefresh(local_wind);
return local_wind;
}

WINDOW *kmil(int heighte, int widthe, int startye, int startxe){

WINDOW *local_wine;

local_wine = newwin(heighte, widthe, startye, startxe);
box(local_wine,0,0);

wbkgd(local_wine,COLOR_PAIR(BACKWIN));

wrefresh(local_wine);
return local_wine;
}

WINDOW *inc(int heightf, int widthf, int startyf, int startxf){

WINDOW *local_winf;

local_winf = newwin(heightf, widthf, startyf, startxf);
box(local_winf,0,0);

wbkgd(local_winf,COLOR_PAIR(BACKWIN));

wrefresh(local_winf);
return local_winf;
}

WINDOW *ftcm(int heightg, int widthg, int startyg, int startxg){

WINDOW *local_wing;

local_wing = newwin(heightg, widthg, startyg, startxg);
box(local_wing,0,0);

wbkgd(local_wing,COLOR_PAIR(BACKWIN));

wrefresh(local_wing);
return local_wing;
}

WINDOW *ydm(int heighth, int widthh, int startyh, int startxh){

WINDOW *local_winh;

local_winh = newwin(heighth, widthh, startyh, startxh);
box(local_winh,0,0);

wbkgd(local_winh,COLOR_PAIR(BACKWIN));

wrefresh(local_winh);
return local_winh;
}

WINDOW *milkm(int heighti, int widthi, int startyi, int startxi){

WINDOW *local_wini;

local_wini = newwin(heighti, widthi, startyi, startxi);
box(local_wini,0,0);

wbkgd(local_wini,COLOR_PAIR(BACKWIN));

wrefresh(local_wini);
return local_wini;
}

/* Functions to destroy windows */

void dwin(WINDOW *local_win){

wborder(local_win,' ', ' ', ' ', ' ', ' ' ,' ', ' ', ' ');
wrefresh(local_win);

delwin(local_win);

}

//*** cmath.h ****/

/* Vinicio Flores -- CMATH -- Makes a lot of maths functions.>
Copyright (C) 2011 Vinicio Flores

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see
*/

#ifndef __CCALC_H
#define __CCALC_H

#define BACKWIN 1
#define TITLECOLOR 2
#define BACKCOLOR 3
#define EXIT_SUCCESS 0
#define BORDER 4

// Defines functions

WINDOW *cwin(int height, int width, int starty, int startx);

WINDOW *mmin(int heighta, int widtha, int startya, int startxa);

WINDOW *cmin(int heightb, int widthb, int startyb, int startxb);

WINDOW *mft(int heightc, int widthc, int startyc, int startxc);

WINDOW *myd(int heightd, int widthd, int startyd, int startxd);

WINDOW *kmil(int heighte,int widthe, int startye, int startxe);

WINDOW *inc(int heightf,int widthf, int startyf, int startxf);

WINDOW *ftcm(int heightg,int widthg, int startyg, int startxg);

WINDOW *ydm(int heighth,int widthh, int startyh, int startxh);

WINDOW *milkm(int heighti,int widthi, int startyi, int startxi);

void dwin(WINDOW *local_win);

void start();
void end();
void title();
void env();

typedef struct {

int y;
int x;

} s;

int height[10],width[10],starty[10],startx[10],ch;

struct {

float mm,cm,m,km,in,ft,yd,mil;

} medidas;

#endif

/* Gracias por su apoyo */