strcpy() son correctas. Más...
#include "str_prtc.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "strcpy.c"
#include <ctype.h>
Namespaces | |
| namespace | std |
Funciones | |
| bool | Verifica (const char *res) |
Ejecuta todas las versiones de strcpy() para constatar que funcionan correctamente con la hilera "res". | |
| void | Dump (const char *name, const char *err_str, unsigned i, str_prtc &blq, const char *res) |
Graba en la salida estándar el contenido completo del bloque de memoria "blq". | |
| void | Mem_Dump (const char *V, unsigned Size) |
Graba en la salida estándar el contenido de "V" en formato hexagesimal. | |
| int | main (int argc, char **argv) |
| Programa principal que contiene todos los datos de prueba. | |
strcpy() son correctas.
|
|
Ejecuta todas las versiones de
00105 { 00106 // Puntero a una función que implementa "strcpy()" pp 156 Stroustrup C++ 00107 00108 char* (*strcpy[9]) (char *dst, const char *src) = { 00109 strcpy_1, strcpy_2, strcpy_3, strcpy_4, strcpy_5, 00110 strcpy_6, strcpy_7, strcpy_8, strcpy_9 00111 }; 00112 // Puntero a una función que implementa "strcpy()" CON "typedef" 00113 typedef char* (*f_strcpy) (char *dst, const char *src); 00114 f_strcpy strcpy_no[] = { 00115 strcpy_1, strcpy_2, strcpy_3, strcpy_4, strcpy_5, 00116 strcpy_6, strcpy_7, strcpy_8, strcpy_9 00117 }; 00118 00119 unsigned DIM_strcpy = 9; // sizeof( *strcpy / *strcpy[0] ); // cantidad de punteros almacenados en "f_strcpy[]" 00120 str_prtc dst, src; 00121 bool error_found = false; 00122 for (unsigned i = 0; i < DIM_strcpy; ++i) { 00123 dst.Fix(); src.Fix(); 00124 dst = ""; // dst.operator= ( "" ); 00125 src = res; // src.operator=( res ); 00126 const char * returned = strcpy[i]( dst, src ); 00127 bool err_1 = ! dst.Ok(); 00128 bool err_2 = ( 0 != memcmp(dst, res, 1+strlen(res)) ); 00129 bool err_3 = ( returned != dst ); 00130 00131 bool err_4 = ! src.Ok(); 00132 bool err_5 = ( 0 != memcmp(src, res, 1+strlen(res)) ); 00133 00134 bool err = (err_1 || err_2 || err_3) || (err_4 || err_5); 00135 char err_str[8]; err_str[0] = 0; 00136 00137 if ( err_1 ) { strcat(err_str,"1"); } if ( err_4 ) { strcat(err_str,"4"); } 00138 if ( err_2 ) { strcat(err_str,"2"); } if ( err_5 ) { strcat(err_str,"5"); } 00139 if ( err_3 ) { strcat(err_str,"3"); } 00140 00141 if ( err_1 || err_2 || err_3 ) { Dump( "dst", err_str, i+1, dst, res); } 00142 if ( err_4 || err_5 ) { Dump( "src", err_str, i+1, dst, res); } 00143 00144 error_found = error_found || err; 00145 } 00146 return error_found; 00147 }
|
|
||||||||||||||||||||||||
|
Graba en la salida estándar el contenido completo del bloque de memoria
ERROR[246]: strcpy_4(src,"alfa") src ==> :FF333333333333333333::31002121212121212121::00CCCCCCCCCCCCCCCCCC: 00167 { 00168 void Mem_Dump(const char* V, unsigned SIZE); // declaración previa de la función 00169 printf("\nERROR[%s", err_str); 00170 printf("]: strcpy_%d(%s,\"%s\")\n%s ==> ", i, name, res, name); 00171 { Mem_Dump(blq.Before(), blq.SIZE_out); 00172 Mem_Dump(blq, blq.SIZE_in); 00173 Mem_Dump(blq.After(), blq.SIZE_out); 00174 } 00175 }
|
|
||||||||||||
|
||||||||||||
|
Programa principal que contiene todos los datos de prueba.
00029 { 00030 00031 /* -- DATOS DE PRUEBA -- */ 00032 00033 char dato1[9] = "LaHilera"; 00034 char dato2[10] = "012345678"; 00035 char dato3[11] = "DarUnError"; 00036 char dato4[9] = "SiCop\0No"; 00037 char dato5[1] = ""; 00038 char dato6[4] = " "; 00039 char dato7[5] = "AB12"; 00040 char dato8[4] = "!?&"; 00041 char dato9[5] = "!?AB"; 00042 char dato10[7] = "AB12!?"; 00043 char dato11[5] = "!?12"; 00044 00045 /* -- Llamados a Verifica( ) utilizando los datos de prueba -- */ 00046 00047 cout << "******* Llamado a Verifica( ) con el dato: " << dato1 00048 << " *******" << endl; 00049 Verifica(dato1); 00050 00051 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00052 << dato2 << " *******" << endl; 00053 Verifica(dato2); 00054 00055 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00056 << dato3 << " *******" << endl; 00057 Verifica(dato3); 00058 00059 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00060 << dato4 << ": 'SiCop'0'No' " << " *******" << endl; 00061 Verifica(dato4); 00062 00063 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00064 << dato5 << " *******" << endl; 00065 Verifica(dato5); 00066 00067 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00068 << dato6 << " *******" << endl; 00069 Verifica(dato6); 00070 00071 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00072 << dato7 << " *******" << endl; 00073 Verifica(dato7); 00074 00075 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00076 << dato8 << " *******" << endl; 00077 Verifica(dato8); 00078 00079 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00080 << dato9 << " *******" << endl; 00081 Verifica(dato9); 00082 00083 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00084 << dato10 << " *******" << endl; 00085 Verifica(dato10); 00086 00087 cout << endl << endl << "******* Llamado a Verifica( ) con el dato: " 00088 << dato11 << " *******" << endl; 00089 Verifica(dato11); 00090 00091 return 0; 00092 }
|
1.4.4