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

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / C++ no se mucho de programación, y tengo varios errores en mi código, indiquenme en que estoy mal, en: 26 Febrero 2022, 19:37 pm
Código
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include <dos.h>
  9. #define size 120
  10.  
  11. struct dire
  12. {
  13. char nombre [30];
  14. char direccion[40];
  15. char tel[11];
  16. char ciudad [20];
  17. char especialidad [20];
  18. char estado[10];
  19. char control[10];
  20. char email[16];
  21. }
  22. dato [size];
  23. char menu (void);
  24. void ver(int,int);
  25. void cua(int,int,int,int);
  26. void llenar(void);
  27. void buscar(void);
  28. void inicia(void);
  29. void guardar(void);
  30. void cargar(void);
  31. void ventana(int,int,int,int,int,int);
  32. void lista (void);
  33. void borrar(void);
  34. void modificar(void);
  35. void gotoxy (int,int);
  36. int regis=0;
  37. FILE *fp;
  38. int main ()
  39. {
  40. char op;
  41. system("cls");
  42. system("Color 7");
  43. system("Color c8");
  44. for(;;)
  45. {
  46. op=toupper(menu());
  47. switch(op)
  48. {
  49. case '1':llenar();
  50. break;
  51. case '2':borrar();
  52. break;
  53. case '3':ver(0,0);
  54. break;
  55. case '4':modificar();
  56. break;
  57. case '5':lista();
  58. break;
  59. case '6':guardar();
  60. break;
  61. case '7':cargar();
  62. break;
  63. case '8':buscar();
  64. break;
  65. case '9':exit(0);
  66. break;
  67. }
  68. }
  69.  
  70. }
  71.  
  72. //---------------------------------------------------------------------
  73. //devolver una seleccion del menu
  74.  
  75.  
  76. char menu (void)
  77. {
  78. char opcion;
  79. system("Color 16");system("cls");
  80. ventana(16,7,61,22,0,2);
  81. ventana(15,8,60,23,4,1);
  82. system("Color 01");
  83. gotoxy(25,9);cprintf("    m     e     n     u    ");
  84. gotoxy(25,12);cprintf("1.- ALTAS");
  85. gotoxy(25,13);cprintf("2.- BAJAS");
  86. gotoxy(25,14);cprintf("3.- CONSULTAS");
  87. gotoxy(25,15);cprintf("4.- MODIFICACIONES");
  88. gotoxy(25,16);cprintf("5.- LISTA");
  89. gotoxy(25,17);cprintf("6.- GUARDAR");
  90. gotoxy(25,18);cprintf("7.- CARGAR");
  91. gotoxy(25,19);cprintf("8.- BUSCAR");
  92. gotoxy(25,20);cprintf("9.- EXIT");
  93. system("Color 08");
  94. gotoxy(31,12);cprintf("1.");gotoxy(31,13);cprintf("2.");
  95. gotoxy(31,14);cprintf("3.");gotoxy(31,15);cprintf("4.");
  96. gotoxy(31,16);cprintf("5.");gotoxy(31,17);cprintf("6.");
  97. gotoxy(31,18);cprintf("7.");gotoxy(31,19);cprintf("8.");
  98. gotoxy(31,20);cprintf("9.");system("Color 04");
  99. gotoxy(31,22);cprintf("Elija una opcion:");
  100. opcion=getch();
  101. system("Color 01");
  102. return(opcion);
  103. }
  104.  
  105.  
  106. //---------------------------------------------------------------------
  107. //inicializa el array
  108.  
  109.  
  110. void inicia (void)
  111. {
  112. register int i;
  113. for (i>0; i<size; i++)
  114. *dato[i].nombre='\0';
  115. }
  116.  
  117.  
  118. //---------------------------------------------------------------------
  119. // introducir datos
  120.  
  121.  
  122. void llenar(void)
  123. {
  124. register int i;
  125. char opc, ar[41];
  126. do
  127. {
  128. cua(5,3,75,24);
  129. for (i=0; i<size; i++)
  130. if(!*dato[i].nombre)
  131. break;
  132. if (i=size)
  133. {
  134. gotoxy(20,10);cprintf("La base esta completa");
  135. return;
  136. }
  137. system("Color 02");
  138. regis++;system("Color 06");
  139. gotoxy(14,6);cprintf("REGISTRO No. %d",regis);
  140. gotoxy(14,8);cprintf("NOMBRE: ");
  141. ar[0]=30;
  142. strcpy(dato[i].nombre, cgets(ar));
  143. gotoxy (14,10);cprintf("DIRECCION: ");
  144. ar[0]=40;
  145. strcpy(dato[i].direccion, cgets(ar));
  146. gotoxy (14,12);cprintf("TELEFONO");
  147. ar[0]=11;
  148. strcpy(dato[i].tel, cgets(ar));
  149. gotoxy (14,14);cprintf("CIUDAD");
  150. ar[0]=20;
  151. strcpy(dato[i].ciudad, cgets(ar));
  152. gotoxy (14,16);cprintf("ESTADO");
  153. ar[0]=10;
  154. strcpy(dato[i].estado, cgets(ar));
  155. gotoxy (14,18);cprintf("EMAIL");
  156. ar[0]=16;
  157. strcpy(dato[i].email, cgets(ar));
  158. system("Color 15");
  159. gotoxy(14,21);cprintf("otro registro (s/n):");
  160. opc=getch();
  161.  
  162.  
  163. }while (toupper (opc)!='n');
  164.  
  165. }
  166.  
  167. //---------------------------------------------------------------------
  168. // eliminar registros completos
  169.  
  170.  
  171.  
  172. void borrar()
  173. {
  174.  
  175. int num;
  176. int ban=0;
  177. int l;
  178. char e,opc;
  179. int var;
  180. int i;
  181. do
  182. {
  183. system("cls");
  184. cua(5,3,75,24); system("Color 01");
  185. gotoxy(18,10);cprintf("QUE REGISTRO DESEA BORRAR: ");
  186. scanf("%d",num);
  187. if (num-1<0 | num>regis)
  188. {
  189. system("Color 03");
  190. //blink
  191. gotoxy(20,13);cprintf("---- NO EXISTE ESE REGISTRO!!! ----");
  192. system("Color 10");
  193. gotoxy(30,21); cprintf ("ELIMINA REGISTRO(S/N): ");
  194. opc=getch();
  195. continue;
  196. gotoxy(0,0);cprintf("");
  197. }
  198. for(i=00 ; i<=num-1; i++) //busca el registro
  199. var=i;
  200. ver (var,1);
  201. system("Color 15");
  202. gotoxy(5,20), cprintf("confirma la eliminacion del registro (presiona S)");
  203. e=getch();
  204. if(toupper(e) =='S')
  205. {
  206.  
  207. for (i=1; i<size; i++)
  208. {
  209. strcpy(dato[i].nombre,dato[i+1].nombre);
  210. strcpy(dato[i].direccion,dato[i+1].direccion);
  211. strcpy(dato[i].tel,dato[i+1].tel);
  212. strcpy(dato[i].ciudad,dato[i+1].ciudad);
  213. strcpy(dato[i].estado,dato[i+1].estado);
  214. strcpy(dato[i].email,dato[i+1].email);
  215. *dato[size].nombre='\0';
  216. }
  217. ban=1;
  218. }
  219. if (ban)
  220. {
  221.  
  222. gotoxy(10,22); cprintf("El registro fue eliminado");
  223. regis--;
  224. }
  225. else
  226. {
  227. gotoxy(10,22); cprintf("La operacion fue cancelada");
  228. }
  229. system("Color 04");
  230. gotoxy(40,22); cprintf ("ELIMINA OTRO REGISTRO (S/N): ");
  231.  
  232. opc=getch();
  233. } while (toupper  (opc) == 'N');
  234. }
  235.  
  236.  
  237. //---------------------------------------------------------------------
  238. // modificaciones
  239.  
  240.  
  241. void modificar(void)
  242. {
  243. int num, el,mod,ban=0;
  244. char e,opc,o,m,dat[41];
  245. register int i, var;
  246. do{
  247. system("cls"); cua (8,5,60,20);   system("Color 10");
  248. gotoxy (20,8);cprintf("QUE REGISTRO DESEA MODIFICAR: ");
  249. scanf("%d",&num);
  250. if (num-1<0 || num>regis)
  251. {
  252. system("Color 06");
  253. //blink
  254. gotoxy(15,13);cprintf("---- NO EXISTE ESE REGISTRO!!! ----");
  255. system("Color 14");
  256. gotoxy(20,17); cprintf ("MODIFICAR REGISTRO(S/N): ");
  257. opc=getch();
  258. continue;
  259. }
  260. for (i=0; i<=num-1; ++) //busca el registro
  261. var=i;
  262. ver (var,1);
  263. do
  264. {
  265. system("Color 10");
  266. gotoxy(5,21); cprintf("1. Nombre   2. Direccion    3. Telefono    4. Ciudad    5. Estado    6. Email     7. Cancelar");
  267. gotoxy(12,23);cprintf("QUE CAMPO DESEA MODIFICAR: ");
  268. m=getch();
  269. //scanf("%d",&mod);
  270. switch(m)
  271. {
  272. case '1':
  273. {
  274. gotoxy(23,8);cprintf("   ");
  275. gotoxy(23,8); dat[0]=30;
  276. strcpy (dato[var].nombre,cgets(dat));
  277. }
  278. break;
  279.  
  280. case '2':
  281. {
  282. gotoxy(26,10);cprintf("   ");
  283. gotoxy(26,10); dat[0]=40;
  284. strcpy (dato[var].direccion,cgets(dat));
  285. }
  286. break;
  287.  
  288. case '3':
  289. {
  290. gotoxy(25,12);cprintf("    ");
  291. gotoxy(25,12); dat[0]=11;
  292. strcpy (dato[var].tel,cgets(dat));
  293. }
  294. break;
  295.  
  296. case '4':
  297. {
  298. gotoxy(23,14);cprintf("    ");
  299. gotoxy(23,14); dat[0]=21;
  300. strcpy (dato[var].ciudad,cgets(dat));
  301. }
  302. break;
  303.  
  304. case '5':
  305. {
  306. gotoxy(23,16);cprintf("    ");
  307. gotoxy(23,16); dat[0]=16;
  308. strcpy (dato[var].estado,cgets(dat));
  309. }
  310. break;
  311.  
  312. case '6':
  313. {
  314. gotoxy(23,18);cprintf("    ");
  315. gotoxy(23,18); dat[0]=16;
  316. strcpy (dato[var].email,cgets(dat));
  317. }
  318. break;
  319.  
  320. default:
  321. {
  322. ban=1;
  323. }
  324. break;
  325. }
  326. system("Color 04");
  327. gotoxy(45,23); cprintf("MODIFICAR OTRO CAMPO(S/N): ");
  328. o=getch();
  329.  
  330. }while (toupper (o)!='N' && ban!=1);
  331. gotoxy(20,21);cprintf("EL CAMPO TECLEADO NO EXISTE");
  332. system("Color 04");
  333. gotoxy(45,23); cprintf("MODIFICAR OTRO REGISTRO (S/N): ");
  334. opc= getch();
  335. } while (toupper(opc)!='N');
  336. }
  337.  
  338.  
  339. //---------------------------------------------------------------------
  340. // busqueda por nombre
  341.  
  342.  
  343. void buscar(void)
  344. {
  345. char alias[40],opc,*p;
  346. register int i;
  347. int found=0;
  348. do
  349. {
  350. system("cls"); cua(8,5,70,23);
  351. gotoxy(10,10);cprintf("nombre a buscar: ");
  352. alias[0]=30;
  353. p=cgets(alias);
  354. for (i=0; i<=regis; i++)
  355. {
  356. if(!stricmp(p,dato[i].nombre))
  357. {
  358. ver (i,1);
  359. found=1;
  360. break;
  361. }
  362. }
  363. system("cls");
  364. if(!found)
  365. {
  366. system("Color 03");
  367. //blink
  368. gotoxy(10,15);cprintf("---- LA PERSONA NO ESTA REGISTRADA!!! ----");
  369. getch(); system("Color 15");
  370. gotoxy(20,21);cprintf("BUSCAR OTRO REGISTRO (S/N): ");
  371. opc = getch();
  372. found=0;
  373. }while (toupper(opc)!='N');
  374. }
  375.  
  376.  
  377. //---------------------------------------------------------------------
  378. // recuperar el archivo de catalogo
  379.  
  380. void cargar(void)
  381. {
  382.  
  383. register int i;
  384. if((fp=fopen("c:\\datos.txt","r+b")) == NULL)
  385. {
  386. printf("No se puede abrir el archivo \n");
  387. return;
  388. }
  389. inicia();
  390. for(i=0; i<size; i++)
  391. {
  392. if(fread(&dato[i],sizeof(struct dire), 1, fp) !=1)
  393. {
  394. regis++;
  395. if(feof(fp))
  396. {
  397. fclose(fp);
  398. return;
  399. }
  400. }
  401. gotoxy(10,10);cprintf("Error al leer el archivo\n");
  402. }
  403. }
  404.  
  405.  
  406. //---------------------------------------------------------------------
  407. // guardar
  408.  
  409.  
  410. void guardar (void)
  411. {
  412. FILE *fp;
  413. register int i;
  414. if((fp=fopen("c:\\datos.txt","w+b"))==NULL)
  415. {
  416. printf("no se puede abrir el archivo");
  417. return;
  418. }
  419. for (i=0; i<size; i++)
  420. {
  421. if (*dato[].nombre)
  422. {
  423. if (fwrite(&dato[i],sizeof(struct dire),1,fp)!=1)
  424. {
  425. gotoxy(10,10);printf("Error de escritura de archivo");
  426. }
  427. }
  428. }
  429. fclose(fp);
  430. }
  431.  
  432.  
  433. //---------------------------------------------------------------------
  434. // ver los datos de la persona
  435.  
  436.  
  437. void ver (int n, int opci)
  438. {
  439. int num,bool=1;
  440. cua(8,8,55,23); system("cls");
  441. textcolor(6);
  442. cua();
  443. if(!opci)
  444. {
  445. gotoxy(20,5);cprintf("QUE REGISTRO DESEAS VISUALIZAR: ");
  446. scanf("%d",&num);
  447. num--;
  448. }
  449. else
  450. num=n;
  451. clrscr();
  452. textbackground(9); textcolor(2);
  453. cua(1,1,75,24);
  454. gotoxy(40,2);cprintf("REGISTRO No. %d",num+1);
  455. textcolor(8);
  456. if (!regis)
  457. {
  458. bool=0;
  459. gotoxy(15,15); cprintf("BASE VACIA");
  460. }
  461. if ((num<0)||(num>regis))
  462. {
  463. bool=0;
  464. gotoxy(15,15); cprintf("NO EXISTE ESE REGISTRO");
  465. }
  466. if(bool)
  467. {
  468. cua(2,3,75,24); textcolor(10);
  469. gotoxy(30,4);cprintf("REGISTRO No.%d",num+1);
  470. gotoxy(15,8);cprintf("NOMBRE:%S",DATO[num].nombre);
  471. gotoxy(15,10);cprintf("DIRECCION:%s".dato[num].direccion);
  472. gotoxy(15,12);cprintf("TELEFONO:%".dato[num].telefono);
  473. gotoxy(15,14);cprintf("CIUDAD:%s".dato[num].ciudad);
  474. gotoxy(15,16);cprintf("ESTADO:%s".dato[nm].estado);
  475. gotoxy(15,18);cprintf("EMAIL:%".dato[num].email);
  476. }
  477. textcolor(14);
  478. gotoxy(45,24); cprintf("Presiona enter para continuar");
  479. }
  480.  
  481.  
  482. //---------------------------------------------------------------------
  483. // lista de personas capturadas
  484.  
  485.  
  486. void lista()
  487. {
  488. register int i=0;
  489. int c=2,cot=0;
  490. system("cls");
  491. cua(1,1,75,24);
  492. while(*dato[i].nombre!='\0' || *dato[i].tel!='\0')
  493. {
  494. cot=i+1;
  495. textcolor(15);
  496. gotoxy(5,c); cprintf("%d. - %s",cot,dato[i].nombre);
  497. i++;
  498. c++;
  499. if (c==22)
  500. {
  501. textcolor(14);
  502. gotoxy(40,24); cprintf("presiona enter para continuar");
  503. system("cls");
  504. c=2;
  505. }
  506. }
  507. gotoxy(40,24); cprintf("presiona enter para terminar");
  508. }
  509.  
  510.  
  511. //---------------------------------------------------------------------
  512. //
  513.  
  514. void cua(int a, int b, int c, int d)
  515. {
  516. int i;
  517. system("color 14");
  518. system("cls");
  519. for(i=a; i<=c; i++)
  520. {
  521. gotoxy(i,b); cprintf("Ä");
  522. gotoxy(i,d); cprintf("Ä");
  523. }
  524. for(i=b; i<=d; i++)
  525. {
  526. gotoxy(a,i); cprintf("Ë");
  527. gotoxy(C,i); cprintf("Ë");
  528. }
  529. gotoxy(a,b); cprintf("Ú");
  530. gotoxy(a,d); cprintf("Á");
  531. gotoxy(c,b); cprintf("?");
  532. gotoxy(c,d); cprintf("Ú");
  533. }
  534.  
  535. //---------------------------------------------------------------------
  536.  
  537.  
  538. void ventana(int a, int b, int c, int d, int e, int f)
  539. {
  540. int i,j;
  541. system("color 5e");
  542.  
  543. for (i=a; i<=c; i++)
  544. {
  545. for (j=b; j<=d; j++)
  546. {
  547. switch(f)
  548. {
  549. case '1':
  550. {
  551. gotoxy(i,j);cprintf("**");
  552. }
  553. break;
  554. case '2':
  555. {
  556. gotoxy(i,j);cprintf("++");
  557. }
  558. break;
  559. }
  560. }
  561. }
  562. }
  563.  

MOD: Etiquetas GeSHi
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines