RV: getchar still with problems

Search this archive.

From: Cristian Sanchez (cristians@arnet.com.ar)
Date: Wed 06 Sep 2000 - 16:44:21 IDT


 Nicolas:
 I think the problem with this code is that you haven't reverved the memory
 for the "contactos" pointer, you have declared the pointer but never
 reserved the necesary physical memory. You can use NEW or MALLOC in order
to
 reserve it. It's a common mistake!. That's why you receive a CORE DUMPED
 ERROR.

 I hope I help you.

 Cristian


> ----- Mensaje original -----
> De: Nicolas Raitman <new_world@radar.com.ar>
> Para: <linux-svgalib@svgalib.org>
> Enviado: 05 September 2000 22:34
> Asunto: getchar still with problems
>
>
> > Look at the comments and pliiiiiiiiiiiiiiiiiiisssssssssss help.
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <vgagl.h>
> > #include <vga.h>
> > #include <string.h>
> > #include <unistd.h>
> > #include <fcntl.h>
> >
> > struct fecha {
> >  int dia;
> >  int mes;
> >  int anio;
> >  };
> >
> > struct personas {
> >  int id;
> >  char apellido [40];
> >  char nombre [40];
> >  char direccion [50];
> >  char email [40];
> >  char tel1 [40];
> >  char tel2 [40];
> >  struct fecha cumple;
> >  };
> >
> >
> > void limpiar();
> > void llenardatos();
> > void abrir();
> >
> >
> > #define TEXT 0
> > #define VIDEOMODE 12
> >
> > int i, j, rta, xmax, ymax, midx, midy, x1, x2, y1, b, c, fd;
> >
> > GraphicsContext *physical_screen;
> > GraphicsContext *virtual_screen;
> >
> >
> > struct personas *contactos;
> >
> > int main (void)
> > {
> >
> >
> > extern unsigned char *gl_font8x8;
> >
> > vga_disabledriverreport();
> > vga_init();
> > vga_setmode(VIDEOMODE);
> > gl_setcontextvga(VIDEOMODE);
> >
> > physical_screen = gl_allocatecontext();
> > gl_getcontext(physical_screen);
> > gl_setcontextvgavirtual(VIDEOMODE);
> > virtual_screen = gl_allocatecontext();
> > gl_getcontext(virtual_screen);
> > gl_setcontext(virtual_screen);
> > gl_setfont(8,8,gl_font8x8);
> > gl_setwritemode(FONT_COMPRESSED + WRITEMODE_MASKED);
> >
> > xmax = vga_getxdim();
> > ymax = vga_getydim();
> > midx = xmax / 2;
> > midy = ymax / 2;
> >
> >
> >
> >
> >
> > gl_clearscreen(0);
> > vga_setmode(TEXT);
> >
> > exit(EXIT_SUCCESS);
> > }
> >
> >
> >
> >
> > void abrir ()
> > {
> >
> > if(fd = open("contactos.dat", O_CREAT, 0644) < 0) {
> >  mensaje("Hubo un error al abrir el Archivo");
> >  exit(EXIT_FAILURE);
> >  }
> > }
> >
> >
> > void agregar()
> > {
> > abrir();
> > llenardatos();
> > }
> >
> > void llenardatos (void)
> > {
> >
> > limpiar();
> > gl_printf(300,100,"Apellido");
> > gl_copyscreen(physical_screen);
> >
> > i = 0;
> >
> > /* i believe the problem is here. When this line arrives i get a
> > segmentation fault. Signal 11. Core  Dumped. Im not sure, but perhaps
> there
> > is something bad with the structures. Please test the code and see in
> which
> > way it can work: receiving the characters and printing it to the
location.
> > (I will make the 'cursor' to move, dont worry, but for now i just want
to
> > see where is the mistake and in which way I can get a char, store it in
> the
> > structure and printing it. */
> >
> > while((contactos->apellido[i] = getchar()) != '\n') {
> >  gl_printf(600,100, "%c", contactos->apellido[i]);
> >  gl_copyscreen(physical_screen);
> >  i++;
> >  }
> >
> >
> > getchar();
> > }
> >
> >
> > void limpiar(void)
> > {
> > gl_clearscreen(0);
> > }
> >
> >
>


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST