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

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Pseudopunteros
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Pseudopunteros  (Leído 1,140 veces)
85

Desconectado Desconectado

Mensajes: 206



Ver Perfil WWW
Pseudopunteros
« en: 19 Marzo 2013, 10:26 am »

Estaba mirando este topic
http://foro.elhacker.net/programacion_cc/es_posible_hacer_esto_sin_arreglos-t385430.0.html
y se me ocurrió una idea, ya que había dicho chistosamente que se puede resolver con 10 variables, lo cual es cierto pero nunca se trata de usar tantas variables.

Lo que se me ocurrió es utilizar el mismo problema y utilizar las 10 variables
para resolverlo, pero usando aritmética de punteros.

El tema es que en realidad me propuse no usar variables de tipo puntero sino variables simples que guarden valores, en este caso, variables enteras.

una variable ocupa un espacio y tiene una dirección de memoria, eso lo sabemos todos. también sabemos que una variable almacena un valor.
pero ese valor puede ser una dirección de memoria también, tal como
los punteros.

Por eso en este topic voy a mostrar como hacer que con variables simples podamos tratarlas como punteros, obviamente sin usar variables de tipo puntero.

Esto se me ocurrió llamarlo "Pseudopunteros" porque en realidad no son variables de puntero.

En realidad no hay ninguna necesidad de hacer esto, ya que el lenguaje
nos da las variables de puntero para hacer esto. Pero ya que es posible
me parece correcto dejar en claro como se puede hacer.

Tampoco estoy seguro si el término "pseudopunteros" sea el correcto,
estuve buscando por google acerca de esta expresión pero sólo sale
algo relacionado a objetos.

por ejemplo:
http://www.ehow.com/info_11400371_difference-between-static-method-class-method.html
http://users.auth.gr/users/6/9/076096/public_html/courses/DataStructures/Implementations.html

pero no hablan de ninguna definición formal, por lo tanto me parece bien llamar a estas variables así XD.

El problema se trata de ingresar 10 números, listarlos, y decir cuáles se
repitieron y cuántas veces.

Para eso vamos a usar 10 variables enteras, que se van a almacenar en forma una seguida de la otra. Vamos a tomar en cuenta para este ejemplo que un entero son 4 BYTES. y con eso vamos al código directamente:

MODIFICADO
Como no se puede garantizar que las variables locales se almacenen de forma contigua en memoria o en un orden determinado (especificaciones de C++), y por el hecho de que los tamaños de los tipos de datos y de las direcciones de memoria no son iguales en diferentes sistemas (ej: x64), se hicieron algunas modificaciones en el código de la demostración.
No se tomaron en cuenta todos los tipos de datos tampoco porque para la demostración tampoco era necesario.

main.cpp
Código
  1. //
  2. // By 85
  3. // elhacker.net
  4. // etalking.com.ar
  5. // boyscout_arg@hotmail.com
  6. // 2013
  7. //
  8.  
  9. /////////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11. //#include<windows.h>
  12. #include<stdio.h>
  13. #include<stdlib.h>
  14.  
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16.  
  17. void Test1();
  18. void Test2();
  19. void Test3();
  20.  
  21. /////////////////////////////////////////////////////////////////////////////////////////////////
  22.  
  23. int main(){
  24.  
  25. system("cls");
  26. printf("Test1:\n");
  27. Test1();
  28. system("pause");
  29.  
  30. system("cls");
  31. printf("Test2:\n");
  32. Test2();
  33. system("pause");
  34.  
  35. system("cls");
  36. printf("Test3:\n");
  37. Test3();
  38. system("pause");
  39.  
  40. return 0;
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////////////////////////

pseudopointers1.cpp
Código
  1.  
  2. //
  3. // By 85
  4. // elhacker.net
  5. // etalking.com.ar
  6. // boyscout_arg@hotmail.com
  7. // 2013
  8. //
  9.  
  10. /////////////////////////////////////////////////////////////////////////////////////////////////
  11.  
  12. #include<stdio.h>
  13. #include<stdlib.h>
  14. #include<string.h>
  15. #include <typeinfo>
  16.  
  17. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  18.  
  19. // No tenemos garantía de que sean almacenadas contiguamente!
  20. static int entrada1=0;//entrada1+0x0
  21. static int entrada2=0;//entrada1+0x4
  22. static int entrada3=0;//entrada1+0x8
  23. static int entrada4=0;//entrada1+0xC
  24. static int entrada5=0;//entrada1+0x10
  25. static int entrada6=0;//entrada1+0x14
  26. static int entrada7=0;//entrada1+0x18
  27. static int entrada8=0;//entrada1+0x1C
  28. static int entrada9=0;//entrada1+0x20
  29. static int entrada10=0;//entrada1+0x24
  30.  
  31. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  32.  
  33. void Test1(){
  34. /*
  35. ////////////////////////////////////
  36. // Basic check (Designed for 10 variables no more)
  37.  
  38. //int entrada10=0;// Hacerlo cagar XD
  39. printf("Estas direcciones deben estar en forma contigua!\n");
  40. printf("0x%X\n",&entrada1);
  41. printf("0x%X\n",&entrada2);
  42. printf("0x%X\n",&entrada3);
  43. printf("0x%X\n",&entrada4);
  44. printf("0x%X\n",&entrada5);
  45. printf("0x%X\n",&entrada6);
  46. printf("0x%X\n",&entrada7);
  47. printf("0x%X\n",&entrada8);
  48. printf("0x%X\n",&entrada9);
  49. printf("0x%X\n",&entrada10);
  50. int flag_exit=0;
  51. if( ((&entrada2)-((&entrada1)+0x1)) !=0){flag_exit=1; goto error;}
  52. if( ((&entrada3)-((&entrada2)+0x1)) !=0){flag_exit=2; goto error;}
  53. if( ((&entrada4)-((&entrada3)+0x1)) !=0){flag_exit=3; goto error;}
  54. if( ((&entrada5)-((&entrada4)+0x1)) !=0){flag_exit=4; goto error;}
  55. if( ((&entrada6)-((&entrada5)+0x1)) !=0){flag_exit=5; goto error;}
  56. if( ((&entrada7)-((&entrada6)+0x1)) !=0){flag_exit=6; goto error;}
  57. if( ((&entrada8)-((&entrada7)+0x1)) !=0){flag_exit=7; goto error;}
  58. if( ((&entrada9)-((&entrada8)+0x1)) !=0){flag_exit=8; goto error;}
  59. if( ((&entrada10)-((&entrada9)+0x1)) !=0){flag_exit=9; goto error;}
  60. error:
  61. if(flag_exit>0){
  62. printf("It seems they are not stored contiguously. Error %d\n", flag_exit);
  63. system("pause");
  64. return;
  65. }*/
  66.  
  67. ////////////////////////////////////
  68.  
  69. #define XPOINTERTYPE unsigned long
  70. #define XVARTYPE int
  71. //if(sizeof(XVARTYPE) != sizeof(entrada1)) return;
  72. unsigned char OFFS = (unsigned char)sizeof(XVARTYPE);// Up to 255
  73. XPOINTERTYPE entradaX=(XPOINTERTYPE)&entrada1;// Una especie de puntero THIS
  74. XPOINTERTYPE inicio_bloque=(XPOINTERTYPE)&entrada1;
  75. XPOINTERTYPE fin_bloque=(XPOINTERTYPE)&entrada10;
  76. int rep = 0;
  77. const int MAX_NUMB =10;
  78. char* format;
  79. if(!strcmp(typeid(XVARTYPE).name(), "int")) format="%d";
  80. else if(!strcmp(typeid(XVARTYPE).name(), "long")) format="%d";
  81. else if(!strcmp(typeid(XVARTYPE).name(), "long int")) format="%d";
  82. else if(!strcmp(typeid(XVARTYPE).name(), "long long")) format="%d";
  83. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned long")) format="%X";
  84. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned int")) format="%d";
  85. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned short")) format="%d";
  86. else if(!strcmp(typeid(XVARTYPE).name(), "float")) format="%f";
  87. else if(!strcmp(typeid(XVARTYPE).name(), "double")) format="%f";
  88. else if(!strcmp(typeid(XVARTYPE).name(), "double long")) format="%f";
  89. else if(!strcmp(typeid(XVARTYPE).name(), "long double")) format="%f";
  90. else return;
  91.  
  92. for(int i=0;i<MAX_NUMB;i++)
  93. {
  94. printf("Introduzca un número\n");
  95. scanf(format,(XPOINTERTYPE*)entradaX);
  96.  
  97. rep=0;
  98. XPOINTERTYPE apuntador1=(XPOINTERTYPE)&entradaX;//Doble puntero
  99.  
  100. for(XPOINTERTYPE j=inicio_bloque;j<(inicio_bloque+(OFFS*i));j+=OFFS)
  101. {
  102. XPOINTERTYPE apuntador2=(XPOINTERTYPE)&j;//Doble puntero
  103.  
  104. if(**(XVARTYPE**)apuntador1 == **(XVARTYPE**)apuntador2){
  105. rep++;
  106. }
  107. }
  108.  
  109. if(rep)
  110. {
  111. char* info;
  112. if(!strcmp(typeid(XVARTYPE).name(), "int")) info="%d had %d repetitions\n";
  113. else if(!strcmp(typeid(XVARTYPE).name(), "long")) info="%d had %d repetitions\n";
  114. else if(!strcmp(typeid(XVARTYPE).name(), "long int")) info="%d had %d repetitions\n";
  115. else if(!strcmp(typeid(XVARTYPE).name(), "long long")) info="%d had %d repetitions\n";
  116. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned long")) info="%X had %d repetitions\n";
  117. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned int")) info="%d had %d repetitions\n";
  118. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned short")) info="%d had %d repetitions\n";
  119. else if(!strcmp(typeid(XVARTYPE).name(), "float")) info="%f had %d repetitions\n";
  120. else if(!strcmp(typeid(XVARTYPE).name(), "double")) info="%f had %d repetitions\n";
  121. else if(!strcmp(typeid(XVARTYPE).name(), "double long")) info="%f had %d repetitions\n";
  122. else if(!strcmp(typeid(XVARTYPE).name(), "long double")) info="%f had %d repetitions\n";
  123. printf(info,**(XVARTYPE**)apuntador1,rep);
  124. //while(getchar()!='\n');
  125. system("pause");
  126. }
  127.  
  128. entradaX+=OFFS;
  129. }
  130. entradaX=(XPOINTERTYPE)&entrada1;//Arreglar el pseudopuntero THIS
  131.  
  132. for(int k=1;k<=MAX_NUMB;k++)
  133. {
  134. printf(format,*(XVARTYPE*)entradaX);
  135.  
  136. entradaX+=OFFS;
  137. }
  138. printf("\n");
  139. entradaX=(XPOINTERTYPE)&entrada1;//Arreglar el pseudopuntero THIS
  140. }
  141.  
  142. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  143.  

pseudopointers2.cpp
Código
  1. //
  2. // By 85
  3. // elhacker.net
  4. // etalking.com.ar
  5. // boyscout_arg@hotmail.com
  6. // 2013
  7. //
  8.  
  9. /////////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include<stdio.h>
  12. #include<stdlib.h>
  13. #include<string.h>
  14. #include <typeinfo>
  15.  
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17.  
  18. // Vamos a usar un array para asegurarnos de que los 10 enteros
  19. // sean almacenados de forma contigua.
  20. static int entradas[10] = {0};
  21.  
  22. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  23.  
  24. void Test2(){
  25.  
  26. #define XPOINTERTYPE unsigned long
  27. #define XVARTYPE int
  28. //if(sizeof(XVARTYPE) != sizeof(entradas[0])) return;
  29. unsigned char OFFS = (unsigned char)sizeof(XVARTYPE);// Up to 255
  30. XPOINTERTYPE entradaX=(XPOINTERTYPE)&entradas[0];// Una especie de puntero THIS
  31. XPOINTERTYPE inicio_bloque=(XPOINTERTYPE)&entradas[0];
  32. XPOINTERTYPE fin_bloque=(XPOINTERTYPE)&entradas[9];
  33. int rep = 0;
  34. const int MAX_NUMB =10;
  35. char* format;
  36. if(!strcmp(typeid(XVARTYPE).name(), "int")) format="%d";
  37. else if(!strcmp(typeid(XVARTYPE).name(), "long")) format="%d";
  38. else if(!strcmp(typeid(XVARTYPE).name(), "long int")) format="%d";
  39. else if(!strcmp(typeid(XVARTYPE).name(), "long long")) format="%d";
  40. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned long")) format="%X";
  41. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned int")) format="%d";
  42. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned short")) format="%d";
  43. else if(!strcmp(typeid(XVARTYPE).name(), "float")) format="%f";
  44. else if(!strcmp(typeid(XVARTYPE).name(), "double")) format="%f";
  45. else if(!strcmp(typeid(XVARTYPE).name(), "double long")) format="%f";
  46. else if(!strcmp(typeid(XVARTYPE).name(), "long double")) format="%f";
  47. else return;
  48.  
  49. for(int i=0;i<MAX_NUMB;i++)
  50. {
  51. printf("Introduzca un número\n");
  52. scanf(format,(XPOINTERTYPE*)entradaX);
  53.  
  54. rep=0;
  55. XPOINTERTYPE apuntador1=(XPOINTERTYPE)&entradaX;//Doble puntero
  56.  
  57. for(XPOINTERTYPE j=inicio_bloque;j<(inicio_bloque+(OFFS*i));j+=OFFS)
  58. {
  59. XPOINTERTYPE apuntador2=(XPOINTERTYPE)&j;//Doble puntero
  60.  
  61. if(**(XVARTYPE**)apuntador1 == **(XVARTYPE**)apuntador2){
  62. rep++;
  63. }
  64. }
  65.  
  66. if(rep)
  67. {
  68. char* info;
  69. if(!strcmp(typeid(XVARTYPE).name(), "int")) info="%d had %d repetitions\n";
  70. else if(!strcmp(typeid(XVARTYPE).name(), "long")) info="%d had %d repetitions\n";
  71. else if(!strcmp(typeid(XVARTYPE).name(), "long int")) info="%d had %d repetitions\n";
  72. else if(!strcmp(typeid(XVARTYPE).name(), "long long")) info="%d had %d repetitions\n";
  73. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned long")) info="%X had %d repetitions\n";
  74. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned int")) info="%d had %d repetitions\n";
  75. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned short")) info="%d had %d repetitions\n";
  76. else if(!strcmp(typeid(XVARTYPE).name(), "float")) info="%f had %d repetitions\n";
  77. else if(!strcmp(typeid(XVARTYPE).name(), "double")) info="%f had %d repetitions\n";
  78. else if(!strcmp(typeid(XVARTYPE).name(), "double long")) info="%f had %d repetitions\n";
  79. else if(!strcmp(typeid(XVARTYPE).name(), "long double")) info="%f had %d repetitions\n";
  80. printf(info,**(XVARTYPE**)apuntador1,rep);
  81. //while(getchar()!='\n');
  82. system("pause");
  83. }
  84.  
  85. entradaX+=OFFS;
  86. }
  87. entradaX=(XPOINTERTYPE)&entradas[0];//Arreglar el pseudopuntero THIS
  88.  
  89. for(int k=1;k<=MAX_NUMB;k++)
  90. {
  91. printf(format,*(XVARTYPE*)entradaX);
  92.  
  93. entradaX+=OFFS;
  94. }
  95. printf("\n");
  96. entradaX=(XPOINTERTYPE)&entradas[0];//Arreglar el pseudopuntero THIS
  97. }
  98.  
  99. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  100.  

pseudopointers3.cpp
Código
  1. //
  2. // By 85
  3. // elhacker.net
  4. // etalking.com.ar
  5. // boyscout_arg@hotmail.com
  6. // 2013
  7. //
  8.  
  9. /////////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include<stdio.h>
  12. #include<stdlib.h>
  13. #include<string.h>
  14. #include <typeinfo>
  15.  
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17.  
  18. // Vamos a usar una estructura para asegurarnos de que los 10 enteros
  19. // sean almacenados de forma contigua.
  20. struct Entradas{
  21. int a,b,c,d,e,f,g,h,i,j;
  22. };
  23.  
  24. static struct Entradas entradas;
  25.  
  26. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27.  
  28. void Test3(){
  29.  
  30. #define XPOINTERTYPE unsigned long
  31. #define XVARTYPE int
  32. //if(sizeof(XVARTYPE) != sizeof(entradas.a)) return;
  33. unsigned char OFFS = (unsigned char)sizeof(XVARTYPE);// Up to 255
  34. XPOINTERTYPE entradaX=(XPOINTERTYPE)&entradas.a;// Una especie de puntero THIS
  35. XPOINTERTYPE inicio_bloque=(XPOINTERTYPE)&entradas.a;
  36. XPOINTERTYPE fin_bloque=(XPOINTERTYPE)&entradas.j;
  37. int rep = 0;
  38. const int MAX_NUMB =10;
  39. char* format;
  40. if(!strcmp(typeid(XVARTYPE).name(), "int")) format="%d";
  41. else if(!strcmp(typeid(XVARTYPE).name(), "long")) format="%d";
  42. else if(!strcmp(typeid(XVARTYPE).name(), "long int")) format="%d";
  43. else if(!strcmp(typeid(XVARTYPE).name(), "long long")) format="%d";
  44. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned long")) format="%X";
  45. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned int")) format="%d";
  46. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned short")) format="%d";
  47. else if(!strcmp(typeid(XVARTYPE).name(), "float")) format="%f";
  48. else if(!strcmp(typeid(XVARTYPE).name(), "double")) format="%f";
  49. else if(!strcmp(typeid(XVARTYPE).name(), "double long")) format="%f";
  50. else if(!strcmp(typeid(XVARTYPE).name(), "long double")) format="%f";
  51. else return;
  52.  
  53. for(int i=0;i<MAX_NUMB;i++)
  54. {
  55. printf("Introduzca un número\n");
  56. scanf(format,(XPOINTERTYPE*)entradaX);
  57.  
  58. rep=0;
  59. XPOINTERTYPE apuntador1=(XPOINTERTYPE)&entradaX;//Doble puntero
  60.  
  61. for(XPOINTERTYPE j=inicio_bloque;j<(inicio_bloque+(OFFS*i));j+=OFFS)
  62. {
  63. XPOINTERTYPE apuntador2=(XPOINTERTYPE)&j;//Doble puntero
  64.  
  65. if(**(XVARTYPE**)apuntador1 == **(XVARTYPE**)apuntador2){
  66. rep++;
  67. }
  68. }
  69.  
  70. if(rep)
  71. {
  72. char* info;
  73. if(!strcmp(typeid(XVARTYPE).name(), "int")) info="%d had %d repetitions\n";
  74. else if(!strcmp(typeid(XVARTYPE).name(), "long")) info="%d had %d repetitions\n";
  75. else if(!strcmp(typeid(XVARTYPE).name(), "long int")) info="%d had %d repetitions\n";
  76. else if(!strcmp(typeid(XVARTYPE).name(), "long long")) info="%d had %d repetitions\n";
  77. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned long")) info="%X had %d repetitions\n";
  78. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned int")) info="%d had %d repetitions\n";
  79. else if(!strcmp(typeid(XVARTYPE).name(), "unsigned short")) info="%d had %d repetitions\n";
  80. else if(!strcmp(typeid(XVARTYPE).name(), "float")) info="%f had %d repetitions\n";
  81. else if(!strcmp(typeid(XVARTYPE).name(), "double")) info="%f had %d repetitions\n";
  82. else if(!strcmp(typeid(XVARTYPE).name(), "double long")) info="%f had %d repetitions\n";
  83. else if(!strcmp(typeid(XVARTYPE).name(), "long double")) info="%f had %d repetitions\n";
  84. printf(info,**(XVARTYPE**)apuntador1,rep);
  85. //while(getchar()!='\n');
  86. system("pause");
  87. }
  88.  
  89. entradaX+=OFFS;
  90. }
  91. entradaX=(XPOINTERTYPE)&entradas.a;//Arreglar el pseudopuntero THIS
  92.  
  93. for(int k=1;k<=MAX_NUMB;k++)
  94. {
  95. printf(format,*(XVARTYPE*)entradaX);
  96.  
  97. entradaX+=OFFS;
  98. }
  99. printf("\n");
  100. entradaX=(XPOINTERTYPE)&entradas.a;//Arreglar el pseudopuntero THIS
  101. }
  102.  
  103. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  104.  

--------------------------------------------------------------------------
EXPLICACIÓN ANTERIOR
--------------------------------
Explico algunas cosas:

Considerando las 10 variables como un bloque de memoria de 10 * 4 BYTES, vamos a guardar la dirección de memoria de comienzo de bloque y la de fin.
Código
  1. int inicio_bloque=(int)&entrada1;
  2. int fin_bloque=(int)&entrada10;

Esta variable guarda la dirección de memoria de la primer variable que
guarda el primer número. Esta variable es como un puntero THIS por así
decirlo, porque se desplaza a lo largo del bloque de 10 variables,
es decir va cambiando su valor al de la dirección de cualquier de las
10 variables enteras. Por lo tanto no tengo drama en llamarla "pseudopuntero" THIS XD.
Código
  1. int entradaX=(int)&entrada1;

Para ingresar 10 números hacemos 10 ciclos, pero el scanf guarda el dato
en la dirección contenida en la variable entradaX. Noten el 'casting', para
que scanf sepa que se trata de un puntero.
Código
  1. for(int i=0;i<MAX_NUMB;i++)
  2. {
  3. printf("Introduzca un numero\n");
  4. scanf("%d",(int*)entradaX);
  5.        ...
  6. }

Citando esta parte, es donde se hace la comparación de cada ingreso contra todos los números ingresados hasta el momento.
Nótese que se utiliza una variable local llamada 'apuntador1' que en realidad hace de doble puntero o puntero a puntero, porque guarda la dirección de otra variable que al mismo tiempo guarda otra dirección de memoria. Por eso para acceder al valor final (un número) se utiliza la notación de doble puntero. En lo que respecta al FOR, como dijimos que son 10 enteros de 4 BYTES cada uno, entonces el FOR cuenta de a 4 BYTES para realizar 10 ciclos.
Código
  1. ...
  2. int apuntador1=(int)&entradaX;//Doble puntero
  3. for(int j=inicio_bloque;j<(inicio_bloque+(0x4*i));j+=0x4)
  4. {
  5. int apuntador2=(int)&j;//Doble puntero
  6.  
  7. if(**(int**)apuntador1 == **(int**)apuntador2){
  8. c++;
  9. }
  10. }
  11.  
  12. ...

También se incrementa la variable entradaX o pseudopuntero THIS,
que apunta al último número o al número actual.
Eso se logra incrementándola en el FOR

Código
  1. entradaX+=0x4;

El tema es que esta variable se reutiliza, por lo cual se debe arreglar su
dirección para que siempre apunte a la primer variable entera.

Código
  1. entradaX=(int)&entrada1;

Inclusive todo esto tiene cierta analogía con el puntero THIS.
Pero quiero aclarar que no es el puntero THIS, es una comparación solamente por eso se le dijo "PSEUDO"

Para listar lo mismo, se le pase a printf el contenido del pseudopuntero.
Código
  1. for(int i=1;i<=MAX_NUMB;i++)
  2. {
  3. printf("%d\n",*(int*)entradaX);
  4.  
  5. entradaX+=0x4;
  6. }

Si por casualidad les parece que mi publicación es una bldez, sepan que entiendo que no estoy descubriendo América, pero está claro que existen las variables de tipo puntero para hacer algo como esto, y no es normal hacerlo con variables comunes, por eso.

CODE:
http://www.mediafire.com/?q3l5yqplduxpfi6

Salu2


« Última modificación: 24 Marzo 2013, 11:53 am por 85 » En línea

Me cerraron el Windows Live Spaces, entonces me creé un WordPress XD
http://etkboyscout.wordpress.com/
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines