Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

zorlack

strange error

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can somebody test this code and tell me qhat id wrong with it
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

const int MAXREG = 500000;
FILE *p = NULL;


struct Data
{
       char *nom;
       int tipo;
       void *data;
};

struct Tabla
{
       bool flag;
       int cant;
       Data valor[5];
};
////////////////////////////////////////////////////////////////////////////////

const char *nombre[39] = { "Jorge", "Marco", "Antonio" ,"Reyes", "Luisa", "Luis", "Carlos",
                   "Mario", "Josue", "Andrea", "Karla", "Jose", "Jesus", "Eduardo",
                   "Gerardo", "Coto", "Sabrina", "Veronica", "Merlin", "Mayra", "Gustavo",
                   "Mercedez", "Flora", "Fabricio", "Allan", "Diego", "Felipe", "Deital",
                   "Walpole", "Omar", "Boing", "Ford", "Lexus", "Valentina", "Suyapa",
                   "Angelica", "Glenda", "Joanna", "Barbara" };

////////////////////////////////////////////////////////////////////////////////

void clrscr()
{
     #ifdef _WIN32
         system("cls");
     #endif
     #ifdef _LINUX_  //Not sure

          system("clear");
     #endif
}

////////////////////////////////////////////////////////////////////////////////

Tabla reg[MAXREG];
Tabla t;
char path[25];
int key;
int tam;
////////////////////////////////////////////////////////////////////////////////

void Menu();
void Creartabla();
void Llenar();

////////////////////////////////////////////////////////////////////////////////

int Main()
{
    Menu();
    srand(time(0));

    do{

       cin >> key;

       if (key < 1 || key > 3)
          clrscr();
       switch(key)
       {
             case 1:
                  Creartabla();
                  clrscr();
                  break;

       }
    }while(key !=3);

}

////////////////////////////////////////////////////////////////////////////////

void Menu()
{
   printf("--------------Menu-------------\n\n");
   printf("1. Crear Un Archivo \n");
   printf("2. Abrir Un Archivo \n");
   printf("3. Salir\n");
   printf("------------------------------\n\n");

}

////////////////////////////////////////////////////////////////////////////////

void Creartabla()
{
     int n, f,tam;
     char nom[10];
     int num;
     float dec;

     printf("-------------------------------\n");
     printf("Numero de Variables: "); cin >> n;
     t.cant = n;
     printf("Typo de Variables: \n");
     cout << "1: int--2: char--3: float " << endl;
     printf("-------------------------------\n");

     for (int i = 0; i < n; i++)
     {
           if (i ==0)
              cout << "LLave...." << endl;
           printf("Nombre de la Variable: ");
           scanf("%s",&nom);
           printf("Escoja tipo de dato: ");
           cin >> f;
           switch(f)
           {
              case 2:
                   cout << "Longitud de la Cadena: ";
                   cin >> tam;
                   break;
            }
            cout << endl;

           t.valor[i].tipo = f;
           t.valor[i].nom = nom;
     }
     Llenar();
}
////////////////////////////////////////////////////////////////////////////////

void Llenar()
{
     int ran, i;

     clock_t seconds;
     clock_t sec;

     seconds =clock();
     for (int x =0; x < MAXREG; x++)
     {
          reg[x].flag= true;
          reg[x].cant = t.cant;
          for (int y = 0; y < t.cant; y++)
          {
              ran = (1 + rand()%500);
              reg[x].valor[y].tipo = t.valor[y].tipo;
              switch (t.valor[y].tipo)
              {
                     case 1:
                          reg[x].valor[y].data = (int *)ran;
                          break;
                     case 2:
                          i = rand()%39;
                          reg[x].valor[y].data = (char*)nombre[i];
                          break;
                     case 3:
                          reg[x].valor[y].data =(float *) ran;
                          break;
              }
              fwrite(®[x].valor[y].data,sizeof(Tabla),1 ,p);
          }


     }

     sec = clock();

     cout << " Se tardo " << (sec - seconds)/1000 << " segundos para llenar el Registro." << endl;

}

Share this post


Link to post
Share on other sites
Advertisement
What''s the exact error msg your getting? In what compiler? What do you want it to do?

When posting any code (even a couple of lines) please put in as much detail as possible. Not everyone wants to look at lines of code, work out what it''s supposed to do, then work out why it''s not doing it.

Share this post


Link to post
Share on other sites
I don't have a compiler to test it out on, but when I was skimming through the code I noticed that you had the m in main capitalized when it shouldn't be. There may be more, but I didn't have time to look through the rest.


[edited by - Bakingsoda36 on August 18, 2003 3:32:35 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!