Hi, well i'm a program that has to show 3 rectangles and a menu (which will add data and then show in the rectangles) to simulate a processor

but i´m getting a problem when the program runs, it shows the rectangles and a the menu right, but when i use the menu the screen goes like gray!!!!!

Why is this? :eek:

AND OTHER QUESTION:

HOW CAN I SHOW THE DATA

(that the user give to the program CALLED LISTA IN THE FUNTION INSERTA = INSERT)
struct Informacion{
char nombre[50];
char montodememoria[100];
char tiempodecalculo[100];
char archivosabiertos[100];
};


IN THE SECOND RECTANGLE ???, and THEN THAT INFORMATION GOES TO THE FIRST RECTANGLE?????

|NOMBRE|<--|NOMBRE |
|--------- |----|-----------|
|_______|----|________|


outtext????

#include <graphics.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define F1 59
#define F2 60
#define ESC 27

struct Informacion{
       char nombre[50];
       char montodememoria[100];
       char tiempodecalculo[100];
       char archivosabiertos[100];
       };

struct Nodo{
       struct Informacion info;
       struct Nodo *sig;
       };

/////////////////////////////////////////////////////////////////////////
///////////////////////////Crea Nodo////////////////////////////////////
struct Nodo *creanodo(struct Informacion data)
 {
   struct Nodo *aux;
   aux=(struct Nodo *)malloc(sizeof(struct Nodo));
   strcpy(aux->info.nombre,data.nombre);
   strcpy(aux->info.montodememoria,data.montodememoria);
   strcpy(aux->info.tiempodecalculo,data.tiempodecalculo);
   strcpy(aux->info.archivosabiertos,data.archivosabiertos);
   return(aux);
 }
///////////////////////////////////////////////////////////////////////
///////////////////////funcion Inserta/////////////////////////////////
void inserta(struct Nodo **Lista, struct Informacion data, int pos)
{
   struct Nodo *aux;
   struct Nodo *aux2;

    if ((pos==1) || (*Lista==NULL))
       {
    aux=creanodo(data);
    aux->sig=*Lista;
    *Lista=aux;
       }
    else{
     int i=1;
     aux=*Lista;
     while (i!=pos-1 && aux!=NULL)
           {
        aux2=aux;
        aux=aux->sig;
        i=i+1;
           }
          if (aux==NULL)
         aux2->sig=creanodo(data);
          else{
           aux2=creanodo(data);
           aux2->sig=aux->sig;
           aux->sig=aux2;
          }
    }
}
////////////////////////////////////////////////////////////////
/////////////////////Funcion Despliega//////////////////////////
void despliega(struct Nodo *Lista)
{
  struct Nodo *aux;
  aux=Lista;
  while(aux!=NULL)
       {
    printf("\n\n%s", aux->info.nombre);
    printf("\n\n%s", aux->info.montodememoria);
    printf("\n%s", aux->info.tiempodecalculo);
    printf("\n%s", aux->info.archivosabiertos);
    aux=aux->sig;
       }
}
/////////////////////////////////////////////////////////////////
int menu()
{
 char opc;
 clrscr();
 printf("\n\n MENU:\n\n\n");
 printf("<<F1>>  Inserta un proceso \n");
 printf("<<F2>>  Aborta    \n");
 printf("<<ESC>> Salir    \n");

 opc=getch();
 if ( (int) opc==0 )
       opc=getch();
 return( (int) opc);
}
////////////////////////////////////////////////////////////////////
///////////////////////funcion inicia grafica//////////////////////
void iniciar_grafica()
{
   int gdriver = DETECT, gmode, errorcode;
   initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
   errorcode = graphresult();
   if (errorcode != grOk)
   {
   printf("Error de grafica: %s\n", grapherrormsg(errorcode));
   printf("presione una tecla para terminar:");
   getch();
   exit(1);
   }
}
/////////////////////////////////////////////////////////////////////
void main()
{
   struct Nodo *Lista=NULL;
   struct Informacion data;
   int pos;
  //
  iniciar_grafica();
  //

   rectangle(20,80,250,350);
   rectangle(420,100,300,350);  //(ESQUINA SUPERIOR IZQUIERDA, ESQUINA INFERIOR DERECH)
   rectangle(440,100,550,350);
   outtextxy(10,20,"SIMULACION DE UN PROCESADOR");
   outtextxy(290,80,"Procesos Activos");
   outtextxy(440,80,"Procesos Inactivos");

   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n Inserta <<F1>>");
   printf("\n Aborta  <<F2>>");
   printf("\n Salir   <<ESC>>");
   getch();
  //
  int accion=0;
  while(accion!=ESC)
  {
   accion=menu();
   clrscr();
   switch(accion)
    {
       case F1: printf("\n\n Inserta un nuevo proceso\n\n");
        printf("\Proporcione:\n");
        printf("\nNombre del programa: ");
        scanf("%s", &data.nombre);
        printf("\nMonto de Memoria: ");
        scanf("%s", &data.montodememoria);
        printf("\nTiempo de Calculo: ");
        scanf("%s", &data.tiempodecalculo);
        printf("\nArchivos Abiertos: ");
        scanf("%s", &data.archivosabiertos);
        printf("\Posicion??: ");
        scanf("%s", &pos);
        inserta(&Lista, data, pos);
        printf("\n­­­Proceso incluido!!! \n");
        break;


       case F2: printf("\n\n Aborta un proceso\n");
        printf("\Proporcione el numero de registro que desea Abortar:\n");
           //    scanf("%d",&pos);
        despliega(Lista);
        // getch();
         break;

       case ESC: printf("\n\n Usted va a salir");
           getch();
           break;
      default: printf("  !!!!!!LA OPCION TECLEADA NO ES VALIDA?????\n\n");
           printf("Presione cualquier tecla para continuar...");
           getch();
       //

       }
         getch();
      }
   //////////////
   closegraph();
   ///////////
}
//////////////////////////////////////////////////////////////////////

The program should do something like the program i include here
but with the extra 'menu' that allows you to insert "data"
,no numbers into the rectangles!!!!

PLEASE HELP ME WITH THIS I CANT CONTINU WITH THE PROGRAM BECAUSE I DONT KNOW HOW TO ADD THE DATA I COLLECTED FROM THE USER IN THE RECTANGLES

Recommended Answers

All 2 Replies

you have to print the data at the same time you print the boxes. With standard C or C++ functions you can't first print the boxes then write over them with data. Do them both at the same time.

Do I have to use

outtextxy(....?

and if i want to print the result of a function
how can I put this

outtextxy(Inserta(*Lista))????????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.