Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - BlackZeroX

#311
Cita de: Fire544 en 10 Agosto 2012, 15:39 PM
BlackZeroX (Astaroth) Comprendo, tienes razon, luego se producirian errores logicos, pero mira esta seria una buena correccion !!


printf("Named Server: ");
    gets(ip);
   
    if(strlen(ip)>=15) //comprobamos que nuestro vector no este al limite de caracteres
    {return 1;} //tambien puedes devolver un mensaje avisando de la falta de espacio


Estas errado, lo mejor es usar una función QUE limite esto... es por ello que en el código que yo publique use fgets(), checa-lo...

Dulces Lunas!¡.
#312
Cita de: GuateGio en 10 Agosto 2012, 09:16 AM
mira tengo este codigo:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
  struct Node* first = NULL;
  struct Node* last = NULL;
  struct Node* temporal = NULL;
  struct Node2* first2 = NULL;
  struct Node2* last2 = NULL;
  struct Node2* temporal2 = NULL;
struct Node{
  int data;
  char nombre;
  int tiempo;
  int quant;
  struct Node* next;
};

struct Node2{
  int data2;
  char nombre2;
  int tiempo2;
  int quant2;
  struct Node2* next2;
};

struct Node* newNode(int data,char nombre, int tiempo,int quant){
  struct Node* New = (struct Node*)malloc(sizeof(struct Node));
  New->data = data;
  New->nombre = nombre;
  New->tiempo = tiempo;
  New->quant = quant;
  New->next = NULL;
  return New;
}

struct Node2* newNode2(int data2,char nombre2, int tiempo2,int quant2){
  struct Node2* New = (struct Node2*)malloc(sizeof(struct Node2));
  New->data2 = data2;
  New->nombre2 = nombre2;
  New->tiempo2 = tiempo2;
  New->quant2 = quant2;
  New->next2 = NULL;
  return New;
}

void agregar(struct Node** first, struct Node** last, int data, char nombre,int tiempo,int quant){
  if(*first == NULL && *last == NULL){
     *first = newNode(data,nombre,tiempo,quant);
     *last = *first;
  }
  else{
     (*last)->next = newNode(data,nombre,tiempo,quant);
     (*last) = (*last)->next;
  }
}
void agregar2(struct Node2** first2, struct Node2** last2, int data2, char nombre2,int tiempo2,int quant2){
  if(*first2 == NULL && *last2 == NULL){
     *first2 = newNode2(data2,nombre2,tiempo2,quant2);
     *last2 = *first2;
  }
  else{
     (*last2)->next2 = newNode2(data2,nombre2,tiempo2,quant2);
     (*last2) = (*last2)->next2;
  }
}

struct Node* borrar(struct Node** first, struct Node** last){
  struct Node* temporal;
  if(*first == NULL && *last == NULL){
     printf("Cola está vacía...\n\n");
     return NULL;
  }
  else if((*first)->next == NULL && (*last)->next == NULL){
     printf("Cola contiene un único elemento...\n\n");
     temporal = *first;
     *first = NULL;
     *last = NULL;
     return temporal;
  }
  else{
     printf("Cola contiene más de un elemento...\n\n");
     temporal = *first;
     *first = (*first)->next;
     return temporal;
  }
}

void mostrar(struct Node* agre){

  //struct Node* temporal = NULL;
  printf("\n");
  //while(agre != NULL){
     printf("%d ", agre->data);
     int id=agre->data;
     char n=agre->nombre;
     int t=agre->tiempo;
     int q=agre->quant;
     cout<<agre->nombre<<" ";      
     printf("%d ", agre->tiempo);
     cout<<agre->quant<<" ";
       if(t > q){
for(int i = (time(NULL) + q); time(NULL) != i; time(NULL));
t=t-q;
cout<<t;
borrar(&first,&last);
agregar(&first, &last, id,n,t,q);
}
else{
for(int i = (time(NULL) + t); time(NULL) != i; time(NULL));
t=t-t;
cout<<t;
borrar(&first,&last);
agregar2(&first2, &last2, id,n,t,q);
}

/*if((temporal = borrar(&first, &last)) != NULL){
              printf("Dequeued value was: %d\n\n", temporal->data);
              free(temporal);
           }*/
           
 /*agre->tiempo = t;
 system("clear");
 cout<<endl<<endl;
 printf("%d ", agre->data);
 cout<<agre->nombre<<" ";
 printf("%d ", agre->tiempo);
         cout<<agre->quant<<" ";*/
 
     //agre = agre->next;
  //}
  printf("\n\n");
}

void mostrar2(struct Node* agre){
while(agre != NULL){
printf("\n");
printf("%d ", agre->data);
     cout<<agre->nombre<<" ";      
     printf("%d ", agre->tiempo);
     cout<<agre->quant<<" ";
     agre = agre->next;
 }
     printf("\n\n");
}
void mostrar3(struct Node* agre,struct Node2* agre2){
while(agre != NULL){
printf("\n");
printf("%d ", agre->data);
     cout<<agre->nombre<<" ";      
     printf("%d ", agre->tiempo);
     cout<<agre->quant<<" ";
     agre = agre->next;
 }
     printf("\n\n");
     while(agre2 != NULL){
printf("\n");
printf("%d ", agre2->data2);
     cout<<agre2->nombre2<<" ";      
     printf("%d ", agre2->tiempo2);
     cout<<agre2->quant2<<" ";
     agre2 = agre2->next2;
 }
     printf("\n\n");
}

int main(){
  //struct Node* first = NULL;
  //struct Node* last = NULL;
  //struct Node* temporal = NULL;
  int data;
  char nombre;
  int tiempo;
  int quant;
  char option = '1';
 
  while(option != 'e' && option != 'E'){
     printf("1)Agregar\n");
     printf("2)Borrar\n");
     printf("3)simular\n");
     printf("4)mostrar\n");
     printf("5)mostrar ambas\n");
     printf("e)Exit ");
     scanf("%c", &option);
     getchar();
     
     switch(option){
        case '1':
           printf("Ingrese ID (int): ");
           scanf("%d", &data);
           cout<<"Ingrese el nombre (int): ";
           cin>>nombre;
           printf("Ingrese el tiempo (int): ");
           scanf("%d", &tiempo);
           cout<<"Ingrese Quantum: ";
           cin>>quant;
           getchar();
           agregar(&first, &last, data,nombre,tiempo,quant);
           printf("\n");
        break;
       
        case '2':
           if((temporal = borrar(&first, &last)) != NULL){
              printf("Valor fue quitado de la cola: %d\n\n", temporal->data);
              free(temporal);
           }
           else printf("No hay ningún valor en la cola...\n\n");
        break;
       
        case '3':
           mostrar(first);
        break;
       
        case '4':
mostrar2(first);
break;
case '5':
mostrar3(first,first2);
break;
       
        case 'e': case 'E':break;
       
        default: printf("No es una opción...\n\n");
     }
  }
 
  return 0;
}



el ingreso de los datos lo hago manual, pero ahora ya no lo quiero hacer manual sino que los datos los obtenga apartir del txt que me van a dar..


crear proceso(1,uno,5,6)
crear proceso(2,dos,4,5)



Gracias por la ayuda

Te recomiendo usar el código del enlace que te deje anteriormente, con algunas modificaciones a la estructura y al codigo.

Por ejemplo en la estructura (organizando mejor los datos):



typedef struct _nodo_ nodo;
typedef struct _datos_ datos;

struct _datos_ {
   long int valor1;
   char* nombre;
   long int valor2;
   long int valor3;
};

struct _nodo_ {
  datos value;
  nodo *siguiente;
  nodo *anterior;
};

#313
Una iteracion es algo que se repite y esto lo realiza un for, while, etc... inclusive la recursividad.

Dulces Lunas!¡.
#314
Si de hecho esta interesante eso de los ActiveX.

Dulces Lunas!¡.
#315
Mira se me ocurre que crees una FUNCIÓN que te extraiga dicho nodo de la lista (Ignoro tu estructura) ya sea solo el valor o la estructura plena, después crea otra función que solo ligue con otra.

Aun así te dejo este enlace de una lista doblemente enlazada.

http://c.conclase.net/edd/?cap=005

En la sección de descargas encuentras el código fuente, pero será mejor que te lees todo eso, en dado caso que no te quede claro o que prefieras textos en ingles tienes la pagina de la Universidad De Stanford (ignoro la liga por ahora).

Dulces Lunas!¡.
#316
@Fire544
No es recomendable usar scanf() de esa manera...

Dulces Lunas!¡.
#317
.
El realizar un strcat() en un buffer es para uno establecido dará POSIBLEMENTE un overflow de indices segun la lontitud de este... por ejemplo:

Código (c,8) [Seleccionar]


#include <stdio.h>
#include <string.h>
#include <windows.h>

int main(){
char puerto[25], ip[25];
char netcat[]="nc"; // produce un error por que aquí solo hay una dimension de 3 indices... y se requiere una aun mas grande...

printf("Introduce la IP:\t");
scanf("%s",&ip);
printf("Introduce el puerto:\t");
scanf("%s",&puerto);
strcat(netcat,ip);
strcat(netcat,puerto);

system(netcat);
while(getchar() !='\n');  
getchar();

}



Estas haciendo la instrucción ya dicha pero dicha instrucción SOLO concatena mas NO redimensiona por lo tando debes tener un 3er buffer donde meter dicha concatenación CON UN BUFFER ADECUADO...



#include <stdio.h>
#include <string.h>
#include <windows.h>

int main()
{
   char *res = NULL;
   const char COMANDO[] = "nc ";
   char puerto[25] = {},
        ip[25] = {},
        buffer[sizeof COMANDO + sizeof puerto + sizeof ip - 2] = {}; // el menos 2 es por que dos de las variables tienen un caracter \0 el cual no nos interesan, por que no restar -3? es simple necesitamos un byte '\0'...

//    printf("%d\n", sizeof buffer); // oslo para saber cuanto buffer tenemos realmente...

   printf("Introduce la IP:\t"); fflush(stdout); // realizo un fflush debido a que en el printf() no termino con \n
   fgets(ip, sizeof puerto - 1, stdin); // con este -1 nos aseguramos que el ultimo byte sea SIEMPRE un \0

   printf("Introduce el puerto:\t"); fflush(stdout); // realizo un fflush debido a que en el printf() no termino con \n
   fgets(puerto, sizeof puerto - 1, stdin); // con este -1 nos aseguramos que el ultimo byte sea SIEMPRE un \0

   strcat(buffer, COMANDO);
   strcat(buffer, ip);
   strcat(buffer, puerto);

   //  sustituimos todos los '\n' por ' '
   res = strpbrk(buffer, "\n");
   while (res) {
       *res = ' ';
       res = strpbrk(res, "\n");
   }

//    puts(buffer); // solo para mostrar el comando...

   system(buffer);

   fflush(stdin); // para que la siguiente instruccion no tenga problemas con el buffer de entrada la vació...
   while(getchar() !='\n');

   return 0;
}



Para mas información: http://www.cplusplus.com/reference/clibrary/cstring/strcat/

Yo me voy a jugar nos vemos.

Dulces Lunas!¡.
#319
Cita de: daniyo en  8 Agosto 2012, 15:22 PM
Yo sigo viendo mejor usar las de boost.

Mejor crear los hilos con el API del sistema operativo, SI ES QUE es solo PARA ESTE sea cual sea...

Dulces Lunas!¡.
#320
Para marcar errores tienen el buffer de salida stderr no usen el stdout.

Dulces Lunas!¡.