elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Temas
Páginas: 1 2 [3]
21  Programación / Programación C/C++ / Warning al compilar un programa [Solucionado] en: 14 Octubre 2012, 01:40 am
Bueno este programita hace lo siguiente: cambia cada letra de la palabra usando abecedario inverso (corrimiento a la derecha)
Cambia 'a' por 'z' - 'y' por 'b' y sucesivamente; el problema es que cuando lo compilo
me lanza este warning:

Código:
[Warning] NULL used in arithmetic 

Alguien sabe por pasa esto y como puedo solucionarlo :huh:
les dejo el code:

Código
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6. char *palabra=(char*)malloc(sizeof(char)*64);
  7. char *nuevo=(char*)malloc(sizeof(char)*64);
  8. char *start= nuevo;
  9. printf("Original: ");
  10. gets(palabra);
  11. while(*palabra!= '\0'){
  12.            if (*palabra==32 )
  13.                *nuevo++= *palabra++;
  14.            else
  15.                *nuevo++= 219- *palabra++;
  16.                }
  17.    *nuevo++='\0';
  18.    printf(" Cifrado: %s \n", start);
  19. return 0;
  20. }

Codigo mejorado  ;D
22  Programación / Programación C/C++ / Se puede dañar el hardware utilizando C/C++ ? en: 9 Octubre 2012, 16:18 pm
 Bueno esa es la duda, que tengo desde que me he iniciado en
C y C++  :rolleyes: me pregunto si se podria dañar el disco o el
microprocesador o tambien la memoria.
 Ejecutando algun tipo de codigo en estos lenguajes, he leido en
algunos sitios que con ASM se puede hacer esto mediante determinadas
instrucciones

Espero que alguien me aclare esto gracias.
23  Programación / Programación C/C++ / Intento de realizar un juego en: 7 Octubre 2012, 15:09 pm
 Comparto con ustedes este codigo para quien le pueda servir,
lo hice en mis tiempos libres y salio esto ;)

Código
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4.  
  5. #define ARRIBA 72
  6. #define IZQUIERDA 75
  7. #define DERECHA 77
  8. #define ABAJO 80
  9. #define ESC 27
  10.  
  11. using namespace std;
  12.  
  13. void mover_izquierda();
  14. void mover_derecha();
  15.  
  16. void juego();
  17.  
  18. char izquierda1[]={' ','0',' ',0};
  19. char izquierda2[]={'0','0','0',0};
  20. char izquierda3[]={'0',' ','0',0};
  21.  
  22. char derecha1[]={' ','0',' ',0};
  23. char derecha2[]={'0','0','0',0};
  24. char derecha3[]={'0',' ','0',0};
  25.  
  26. char tecla;
  27. int x = 0, y = 0;
  28.  
  29. void gotoxy(int x,int y)
  30. {
  31.    HANDLE hCon;
  32.    COORD dwPos;
  33.  
  34.    dwPos.X = x;
  35.    dwPos.Y = y;
  36.    hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  37.    SetConsoleCursorPosition(hCon,dwPos);
  38. }
  39. void juego() {
  40.    x=37;
  41.    y=20;
  42.    do {
  43.       tecla = getch();
  44.       if (tecla == IZQUIERDA || tecla == DERECHA) {
  45.          if (tecla == IZQUIERDA)
  46.           mover_izquierda();
  47.          if (tecla == DERECHA)
  48.           mover_derecha();
  49.        }    
  50.    }while(1);
  51.    cin.get();
  52. }
  53. void mover_izquierda() {
  54.     if (x>=3) {
  55.        x-=3;
  56.        system("cls");
  57.     }
  58.     gotoxy(x,y); puts(izquierda1);
  59.     gotoxy(x,y+1); puts(izquierda2);
  60.     gotoxy(x,y+2); puts(izquierda3);
  61.     gotoxy(0,0);
  62. }
  63. void mover_derecha() {
  64.     if (x<75) {
  65.        x+=3;
  66.        system("cls");
  67.     }
  68.     gotoxy(x,y); puts(derecha1);
  69.     gotoxy(x,y+1); puts(derecha2);
  70.     gotoxy(x,y+2); puts(derecha3);
  71.     gotoxy(0,0);
  72. }
  73. int main() {
  74.    printf("\n\n\t\t\t SPACE INVADERS \n");
  75.    printf("\n\n\n\t\tPRESIONA LAS TECLA <- O -> PARA INICIAR:");
  76.  
  77.    gotoxy(0,0);
  78.    int menu = getch();
  79.    juego();
  80.  
  81.    return 0;
  82. }
  83.  
24  Programación / Programación C/C++ / Juego snake en c++ en: 5 Octubre 2012, 02:20 am
El codigo ya esta corregido, la libreria (conio2.h) es la que provocaba
el fallo; este es el code funcional pa quien lo quiera compilar
y ejecutar gracias a todos ;)

  
Código
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5.  
  6. #define ARRIBA 72
  7. #define IZQUIERDA 75
  8. #define DERECHA 77
  9. #define ABAJO 80
  10. #define ESC 27
  11.  
  12. int cuerpo[200][2];
  13. int n = 1, tam = 10, dir = 3;
  14. int x = 10, y = 12;
  15. int xc = 30, yc = 15;
  16. int velocidad = 60;
  17. char tecla;
  18.  
  19. void gotoxy(int x, int y)
  20. {
  21.    HANDLE hCon;
  22.    COORD dwPos;
  23.  
  24.    dwPos.X = x;
  25.    dwPos.Y = y;
  26.    hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  27.    SetConsoleCursorPosition(hCon,dwPos);
  28. }
  29. void OcultaCursor() {
  30.    CONSOLE_CURSOR_INFO cci = {100, FALSE};
  31.  
  32.    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
  33. }
  34. void pintar(){  
  35.     for(int i=2; i < 78; i++){
  36.        gotoxy (i, 3); printf ("%c", 205);
  37.        gotoxy(i, 23); printf ("%c", 205);
  38.        }
  39.     for(int v=4; v < 23; v++){
  40.        gotoxy (2,v);  printf ("%c", 186);
  41.        gotoxy(77,v);  printf ("%c", 186);
  42.        }
  43.     gotoxy  (2,3);    printf ("%c", 201);
  44.     gotoxy (2,23);    printf ("%c", 200);
  45.     gotoxy (77,3);    printf ("%c", 187);
  46.     gotoxy(77,23);    printf ("%c", 188);
  47.     }  
  48. void guardar_posicion(){
  49.     cuerpo[n][0] = x;
  50.     cuerpo[n][1] = y;
  51.     n++;
  52.     if(n == tam) n = 1;
  53. }
  54. void dibujar_cuerpo(){
  55.      for(int i = 1; i < tam; i++){
  56.      gotoxy(cuerpo[i][0] , cuerpo[i][1]); printf("*");
  57.     }
  58. }
  59. void borrar_cuerpo(){
  60.     gotoxy(cuerpo[n][0] , cuerpo[n][1]); printf(" ");
  61.    }
  62. void teclear(){
  63.     if(kbhit()){
  64.            tecla = getch();
  65.            switch(tecla){
  66.                case ARRIBA : if(dir != 2) dir = 1; break;
  67.                case ABAJO : if(dir != 1) dir = 2; break;
  68.                case DERECHA : if(dir != 4) dir = 3; break;
  69.                case IZQUIERDA : if(dir != 3) dir = 4; break;
  70.           }
  71.     }
  72. }
  73. void comida()
  74. {
  75.     if(x == xc && y == yc)
  76.     {
  77.          xc = (rand() % 73) + 4;
  78.          yc = (rand() % 19) + 4;
  79.  
  80.          tam++;
  81.          gotoxy(xc, yc); printf("%c", 4);
  82.     }
  83. }
  84. bool game_over()
  85. {
  86.     if(y == 3 || y == 23 || x == 2 || x == 77) return false;
  87.     for(int j = tam - 1; j > 0; j--){
  88.             if(cuerpo[j][0] == x &&  cuerpo[j][1] == y)
  89.             return false;
  90.     }
  91.    return true;
  92. }
  93. int main()
  94. {
  95.    OcultaCursor();
  96.  
  97.    pintar();
  98.   gotoxy(xc, yc); printf("%c", 4);
  99.  
  100.    while(tecla != ESC && game_over())
  101.    {
  102.         borrar_cuerpo();
  103.         guardar_posicion();
  104.         dibujar_cuerpo();
  105.         comida();
  106.         teclear();
  107.         teclear();
  108.  
  109.         if(dir == 1) y--;
  110.         if(dir == 2) y++;
  111.         if(dir == 3) x++;
  112.         if(dir == 4) x--;
  113.  
  114.         Sleep(velocidad);
  115.         }
  116.    pintar();
  117.    return 0;
  118. }
Páginas: 1 2 [3]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines