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

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  quien me puede ayudar en el error
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: quien me puede ayudar en el error  (Leído 1,520 veces)
geshiro

Desconectado Desconectado

Mensajes: 178


Ver Perfil
quien me puede ayudar en el error
« en: 15 Junio 2015, 01:44 am »

quien me puede ayudar en el error de la parte de eliminar

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. /*malloc-free-alloc-realloc unsigned*/
  7. struct nodo{//DEFINE LA ESTRUCTURA
  8. char nombre[128];
  9. char fecha[10];
  10. int cuenta;
  11. float saldo;
  12. struct nodo  *ant, *sig; //SE CREA EL APUNTADOR DEL TAMAÑO DE UN NODO SIMILAR
  13. };
  14. typedef struct nodo NODO;//DEFINE TIPO DE DATO A PARTIR DE LA ESTRUCTURA DE nodo
  15. typedef NODO *NODOPTR;//DEFINE UN TIPO DE APUNTADOR BASADO EN EL TAMAÑO DE NODO
  16. int isEmpty(NODOPTR cima){//RECIBE LA CIMA PARA LA COMPARACION
  17. return (cima == NULL);
  18. }
  19. void add(NODOPTR * cima,char nombre[128],char fecha[10],int cuenta,float saldo){
  20. system("cls");
  21. NODOPTR nuevo;//APUNTADOR PARA EL NUEVO DATO
  22. NODOPTR actual;//APUNTADOR TEMPORAL QUE SE UTILIZA CUANDO EXISTE AL MENOS UN DATO
  23. nuevo = (NODO *) malloc(sizeof(NODO));//REGRESA LA DIRECCION DE UN BLOQUE DE MEMORIA EN EL CUAL SE ASIGNARAN LOS VALORES
  24. if(nuevo==NULL){
  25. printf("No se puede agregar");
  26. }else{
  27. if(isEmpty(*cima)){//SE ASIGNAN LOS VALORES RECIBIDOS POR LA FUNCION
  28. strcpy(nuevo->nombre,nombre);
  29. strcpy(nuevo->fecha,fecha);
  30. nuevo->cuenta = cuenta;
  31. nuevo->saldo = saldo;
  32. nuevo->sig = NULL;//SE ASIGNA NULO POR QUE EL PRIMERO
  33. *cima = nuevo;//AL SER EL PRIMERO SE ESTABLECE COMO LA CIMA
  34. }else{
  35. actual = *cima;//SE ALMACENA EL APUNTADOR DE LA CIMA ACTUAL
  36. while(actual->sig != NULL){//SE RECORREN TODOS LOS ELEMENTOS DE LA COLA HASTA ENCONTRAR UN VALOR "NULL" EN LA PROPIEDAD DE SIGUIENTE
  37. actual = actual->sig;//SE ASIGNA LA ESTRUCTURA SIGUIENTE A LA ACTUAL
  38. }
  39. strcpy(nuevo->nombre,nombre);
  40. strcpy(nuevo->fecha,fecha);
  41. nuevo->cuenta = cuenta;
  42. nuevo->saldo = saldo;
  43. nuevo->sig = NULL;
  44. actual->sig = nuevo;//SE ASIGNA EL APUNTADOR DEL NUEVO ELEMENTO AL ULTIMO
  45. }
  46. }
  47. }
  48. void remove(NODOPTR *cima){//RECIBE EL APUNTADOR DONDE SE ENCUENTRA LA CIMA
  49. NODOPTR temp;//SE CREA UN NODO TEMPORAL
  50. temp = *cima;//ALMACENA EL APUNTADOR DE LA CIMA
  51. *cima = (*cima)->sig;//SE ALMACENA EL APUNTADOR DEL SIGUIENTE ELEMENTO EN LA LOCACION DE LA CIMA
  52. free(temp);//SE LIBERA LA LOCACION DE MEMORIA TEMPORAL DONDE SE ENCONTRABA LA CIMA ACTUAL
  53. }
  54. void show(NODOPTR cima){//RECIBE LA CIMA
  55. system("cls");
  56. if(cima == NULL){
  57. printf("La cola esta vacia");
  58. }else{
  59. while(cima != NULL){//RECORRE HASTA ENCONTRAR EL ULTIMO ELEMENTO
  60. printf("-----------------------------------------------------\n");
  61. printf("Numero de cuenta:%d\n",cima->cuenta);
  62. printf("Nombre:%s\n",cima->nombre);
  63. printf("Fecha de nacimiento:%s\n",cima->fecha);
  64. printf("Saldo:%f:\n",cima->saldo);
  65. cima = cima->sig;//SE ASIGNA EL SIGUIENTE A LA CIMA ACTUAL
  66. }
  67. }
  68. getch();
  69. }
  70. int find(NODOPTR cima,int cuenta){//RECIBE LA CIMA
  71. int found = 0;
  72. if(cima == NULL){
  73. printf("La cola esta vacia");
  74. }else{
  75. while(cima != NULL){//RECORRE HASTA ENCONTRAR EL ULTIMO ELEMENTO
  76. if(cima->cuenta == cuenta){
  77. found = 1;
  78. break;
  79. }
  80. cima = cima->sig;//SE ASIGNA EL SIGUIENTE A LA CIMA ACTUAL
  81. }
  82. }
  83. return found;
  84. }
  85. int edit(NODOPTR cima,int cuenta,char nombre[128],char fecha[10]){//RECIBE LA CIMA
  86. int success = 0;
  87. if(cima == NULL){
  88. printf("La cola esta vacia");
  89. }else{
  90. while(cima != NULL){//RECORRE HASTA ENCONTRAR EL ULTIMO ELEMENTO
  91. if(cima->cuenta == cuenta){
  92. strcpy(cima->nombre,nombre);
  93. strcpy(cima->fecha,fecha);
  94. success = 1;
  95. break;
  96. }
  97. cima = cima->sig;//SE ASIGNA EL SIGUIENTE A LA CIMA ACTUAL
  98. }
  99. }
  100. return success;
  101. }
  102. int deposito(NODOPTR cima,int cuenta,int cantidad){//RECIBE LA CIMA
  103. int success = 0;
  104. if(cima == NULL){
  105. printf("La cola esta vacia");
  106. }else{
  107. while(cima != NULL){//RECORRE HASTA ENCONTRAR EL ULTIMO ELEMENTO
  108. if(cima->cuenta == cuenta){
  109. cima->saldo+=cantidad;
  110. success = 1;
  111. break;
  112. }
  113. cima = cima->sig;//SE ASIGNA EL SIGUIENTE A LA CIMA ACTUAL
  114. }
  115. }
  116. return success;
  117. }
  118. int retirar(NODOPTR cima,int cuenta,int cantidad){//RECIBE LA CIMA
  119. int success = 0;
  120. if(cima == NULL){
  121. printf("La cola esta vacia");
  122. }else{
  123. while(cima != NULL){//RECORRE HASTA ENCONTRAR EL ULTIMO ELEMENTO
  124. if(cima->cuenta == cuenta){
  125. if(cima->saldo>=cantidad){
  126. cima->saldo-=cantidad;
  127. success = 1;
  128. break;
  129. }else
  130. printf("No cuenta con el saldo suficiente\n");
  131. }
  132. cima = cima->sig;//SE ASIGNA EL SIGUIENTE A LA CIMA ACTUAL
  133. }
  134. }
  135. return success;
  136. }
  137. //RETORNO DE APUNTADOR
  138. NODOPTR findptr(NODOPTR cima,int cuenta){//RECIBE LA CIMA
  139. NODOPTR found = NULL;
  140. if(cima == NULL){
  141. printf("La cola esta vacia");
  142. }else{
  143. while(cima != NULL){//RECORRE HASTA ENCONTRAR EL ULTIMO ELEMENTO
  144. if(cima->cuenta == cuenta){
  145. found = cima;
  146. break;
  147. }
  148. cima = cima->sig;//SE ASIGNA EL SIGUIENTE A LA CIMA ACTUAL
  149. }
  150. }
  151. return found;
  152. }
  153.  
  154. int borrar(NODOPTR *ptr,int cuenta,NODOPTR *sig)
  155. {
  156. NODOPTR antesptr, actualptr, tempptr;
  157. if(cuenta == (*ptr)-> cuenta)
  158. {
  159. tempptr = *ptr;
  160. *ptr = (*ptr)->sig;
  161. (*ptr)-> ant = NULL;
  162. free(tempptr);
  163. return cuenta;
  164. }
  165. else
  166. {
  167. antesptr = *ptr;
  168. actualptr = (*ptr)->sig;
  169. while(actualptr != NULL && actualptr->cuenta != cuenta)
  170. {
  171. antesptr = actualptr;
  172. actualptr = actualptr->sig;
  173. }
  174. if(actualptr != NULL)
  175. {
  176. tempptr = actualptr;
  177. antesptr->sig = actualptr->sig;
  178. actualptr = actualptr->sig;
  179. actualptr->ant = antesptr;
  180. free(tempptr);
  181.  
  182.         return cuenta;
  183. }
  184. }
  185. return -1;
  186. }
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. int main()
  194. {
  195. NODOPTR cima = NULL;
  196. NODOPTR inicio = NULL, actual = NULL;
  197. /*NODOPTR cuenta_1 = NULL;
  198. NODOPTR cuenta_2 = NULL;*/
  199. int cuenta_1,cuenta_2;
  200. int x = 0;
  201. //Variables
  202. char nombre[128];
  203. char fecha[10];
  204. int cuenta;
  205. float cantidad;
  206. strcpy(nombre,"Roberto");
  207. strcpy(fecha,"1991-06-07");
  208. add(&cima,nombre,fecha,1,1000.00);
  209. strcpy(nombre,"Saul");
  210. strcpy(fecha,"1996-09-30");
  211. add(&cima,nombre,fecha,2,1900.00);
  212. //show(cima);
  213. /*cuenta_1 = findptr(cima,1);
  214. cuenta_2 = findptr(cima,2);
  215. printf("%f\n",cuenta_1->saldo);
  216. printf("%f\n",cuenta_2->saldo);
  217. return 0; */
  218. do{
  219. system("cls");
  220. printf("Seleccione una opcion\n");
  221. printf("1.Agregar\n");
  222. printf("2.Modificar\n");
  223. printf("3.Desplegar cuentas\n");
  224. printf("4.Deposito\n");
  225. printf("5.Retiro\n");
  226. printf("6.Transferencia\n");
  227. printf("7.Eliminar\n");
  228. printf("0.Salir\n");
  229. scanf("%d",&x);
  230. switch(x){
  231. case 1:
  232. system("cls");
  233. printf("Ingrese el nombre del titular:\n");
  234. fflush(stdin);
  235. gets(nombre);//fgets(nombre,sizeof(nombre),stdin);
  236. system("cls");
  237. printf("Ingrese la fecha de nacimiento del titular:\n");
  238. fflush(stdin);
  239. gets(fecha);//fgets(fecha,sizeof(fecha),stdin);
  240. do{
  241. system("cls");
  242. printf("Ingrese el numero de cuenta del titular:\n");
  243. scanf("%d",&cuenta);
  244. }while(find(cima,cuenta)==1);
  245. add(&cima,nombre,fecha,cuenta,0.00);
  246. system("pause");
  247. break;
  248. case 2:
  249. do{
  250. system("cls");
  251. printf("Ingrese el numero de cuenta:\n");
  252. scanf("%d",&cuenta);
  253. }while((find(cima,cuenta))==0);
  254. if(cuenta != 0){
  255. system("cls");
  256. printf("Ingrese el nombre del titular:\n");
  257. fflush(stdin);
  258. gets(nombre);
  259. system("cls");
  260. printf("Ingrese la fecha de nacimiento del titular:\n");
  261. fflush(stdin);
  262. gets(fecha);
  263. if(edit(cima,cuenta,nombre,fecha)==1)
  264. printf("Sus datos fueron almacenados\n");
  265. else
  266. printf("Hubo un error al almacenar sus datos\n");
  267. }
  268. system("pause");
  269. break;
  270. case 3:
  271. show(cima);
  272. system("pause");
  273. break;
  274. case 4:
  275. do{
  276. system("cls");
  277. printf("Ingrese el numero de cuenta:\n");
  278. scanf("%d",&cuenta);
  279. }while((find(cima,cuenta))==0);
  280. if(cuenta != 0){
  281. system("cls");
  282. printf("Ingrese la cantidad a depositar:\n");
  283. scanf("%f",&cantidad);
  284. if(deposito(cima,cuenta,cantidad)==1)
  285. printf("Deposito realizado con exito\n");
  286. else
  287. printf("Hubo un error al depositar\n");
  288. }
  289. system("pause");
  290. break;
  291. case 5:
  292. do{
  293. system("cls");
  294. printf("Ingrese el numero de cuenta:\n");
  295. scanf("%d",&cuenta);
  296. }while((find(cima,cuenta))==0);
  297. if(cuenta != 0){
  298. system("cls");
  299. printf("Ingrese la cantidad a retirar:\n");
  300. scanf("%f",&cantidad);
  301. if(retirar(cima,cuenta,cantidad)==1)
  302. printf("Retiro realizado con exito\n");
  303. else
  304. printf("Hubo un error al retirar\n");
  305. }
  306. system("pause");
  307. break;
  308. case 6:
  309. do{
  310. system("cls");
  311. printf("Ingrese el numero de cuenta benefactora:\n");
  312. scanf("%d",&cuenta_1);
  313. }while((find(cima,cuenta_1))==0);
  314. do{
  315. system("cls");
  316. printf("Ingrese el numero de cuenta beneficiario:\n");
  317. scanf("%d",&cuenta_2);
  318. }while((find(cima,cuenta_2))==0);
  319. if(cuenta_1 != 0 && cuenta_2 != 0){
  320. system("cls");
  321. printf("Ingrese la cantidad a transferir:\n");
  322. scanf("%f",&cantidad);
  323. if(retirar(cima,cuenta_1,cantidad)==1){
  324. if(deposito(cima,cuenta_2,cantidad))
  325. printf("Transferencia realizada con exito\n");
  326. }else
  327. printf("Hubo un error al retirar\n");
  328. }
  329. system("pause");
  330. break;
  331. case 7:
  332.   if(!isEmpy(inicio))
  333. {
  334. printf("\n Cual cuenta sera borrado ?");
  335. scanf("%d",&cuenta);
  336. if(borrar(&actual,cuenta,&actual))
  337. {
  338. printf("\n %d ha sido borrado",cuenta);
  339. show(cima);
  340. }
  341. else
  342. printf("\n %d no pudo ser borrado",cuenta);
  343. }
  344. else
  345. printf("\n La lista esta vacia ");
  346. getch();
  347.   break;
  348. }
  349. }while(x!=0);
  350.  
  351. return 0;
  352. }
  353.  


En línea

ivancea96


Desconectado Desconectado

Mensajes: 3.412


ASMático


Ver Perfil WWW
Re: quien me puede ayudar en el error
« Respuesta #1 en: 15 Junio 2015, 15:37 pm »

Pon el error por aquí.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Quien me puede ayudar con el photoshop
Diseño Gráfico
jason 7 3,246 Último mensaje 2 Mayo 2004, 06:19 am
por skamilo
Quien me puede ayudar con el reset!!
Electrónica
yahikochan1 0 1,945 Último mensaje 1 Septiembre 2006, 02:21 am
por yahikochan1
quien me puede ayudar con el debug??
Scripting
~[uNd3rc0d3]~ 2 2,148 Último mensaje 13 Diciembre 2007, 23:27 pm
por ~[uNd3rc0d3]~
QUIEN ME PUEDE AYUDAR CON ESTO?? « 1 2 »
Dudas Generales
romy_03 10 5,310 Último mensaje 20 Mayo 2013, 21:08 pm
por simorg
quien me puede ayudar
Programación C/C++
geshiro 2 1,601 Último mensaje 15 Marzo 2015, 18:45 pm
por geshiro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines