Article View: es.comp.os.linux.programacion
Article #10995Re: Problemas con scanf en C
From: Ángel Suárez Rivero
Date: Sun, 06 Jan 2002 15:28
Date: Sun, 06 Jan 2002 15:28
113 lines
4310 bytes
4310 bytes
--nextPart1407507.y0tfPnE92U
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
Javier Beltr�n S�nchez wrote:
> Hola a todos, antes de nada voy a poner el codigo del programa para
> que sea mas facil explicar el problema.
Hala, he hecho un par de cambios: Busca los comentarios en el c�digo.
--
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
owGbwMvMwCR4mlF2Vp79x72Ma04kcekVZ6bnJZaUFqXasFbeDUgsSsnPU0jLL1LI
rVRwzUvPySzO4LLVJRNy1XA6+Lm7+nAWFyXmpafmOJSk5qTmZOal6qUWcxbklySW
5CsY6VUqFGQm53PWUGBPhz0zKwPIAzC/CTIV9zPMU7ypfjl0seSXuFSvXROCH7F5
fem2ZJifuOGfelOH1nE32yfv2hR5Mi6lHTEGAA==
=tKD8
-----END PGP MESSAGE-----
--nextPart1407507.y0tfPnE92U
Content-Type: text/x-csrc; name="dni.c"
Content-Transfer-Encoding: 8Bit
Content-Disposition: attachment; filename="dni.c"
#include <stdio.h>
#include <stdlib.h> /* Este para la funci�n system */
char opciones;
char nif[23] = { 'T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B',
'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E' };
int nifdos;
int dni;
int paso1;
int paso2;
int paso3;
int main (void)
{
system ("clear");
/* OPCIONES DEL PROGRAMA */
printf ("\n A)- Insertar DNI para saber el NIF");
printf ("\n B)- Generar DNIs a partir del NIF");
printf ("\n C)- Generar tabla de DNI aleatorios");
printf ("\n D)- Verificar si un DNI es verdadero\n");
/* FIN OPCIONES */
printf ("\n � Que opcion deseas ? ");
scanf ("%c", &opciones);
/* CONDICIONES */
if (opciones == 'a' || opciones == 'A') {
/* CONDICION A */
printf ("\n Has escogido la opcion A");
printf ("\n Inserta el numero de DNI para saber el NIF: ");
scanf ("%i", &dni);
if ( dni <= 0 || dni >= 99999999 ){
/* Aqu� dni<=0 && dni>=99999999 y a�ado | */
printf(" ERROR! Tienes que introducir correctamente"
"los nueve digitos del DNI\n\n ");
} else {
/* PASOS PARA CALCULAR EL NIF */
paso1 = dni / 23;
paso2 = paso1 * 23;
paso3 = dni - paso2;
printf ("\n Primer paso (dni/23): "); //paso1
printf ("%i", paso1);/* Aqu� omito '&'*/
printf ("\n Segundo paso (dni*23): "); //paso2
printf ("%i", paso2);/* Aqu� omito '&'*/
printf ("\n Tercer paso (dni-paso2): "); //paso3
printf ("%i", paso3);/* Aqu� omito '&'*/
printf ("\n DNI con NIF: "); //paso4
printf ("%i-%c\n\n", dni, paso3[nif]);
}
}
else /* A�ado else */
if (opciones == 'd' || opciones == 'D') {
/* CONDICION D */
printf ("\n -------------------------------------------------");
printf ("\n | TABLA DE NIFS |");
printf ("\n -------------------------------------------------");
printf ("\n | T | R | W | A | G | M | Y | F | P | D | X | B |");
printf ("\n | N | J | Z | S | Q | V | H | L | C | k | E | T |");
printf ("\n -------------------------------------------------");
printf ("\n Inserta la letra del DNI que quieres comprobar ");
scanf ("%i", &nifdos);
if (nifdos == 't') {
printf (" Es t ");
}
}
else
fprintf(stdout, "MAL en entrada: dni [a, d]\n"); /* Aqu� a�ado un abiso */
return 0;
}
--nextPart1407507.y0tfPnE92U--
Technical Details
Message-ID:
<9eq91a.lf.ln@127.0.0.1>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newsfeed.bcn.ttd.net!news.mad.ttd.net!127.0.0.1!nobodyReferences:
<ab4993a4.0201051629.2d4139ef@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,e82b9e3d7d9c7f8a X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-01-06 07:25:19 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newsfeed.bcn.ttd.net!news.mad.ttd.net!127.0.0.1!nobody From: Ángel Suárez Rivero <srangel@teleline.es> Newsgroups: es.comp.os.linux.programacion Subject: Re: Problemas con scanf en C Date: Sun, 06 Jan 2002 15:28:09 +0000 Organization: Telefonica Transmision de Datos Lines: 113 Message-ID: <9eq91a.lf.ln@127.0.0.1> References: <ab4993a4.0201051629.2d4139ef@posting.google.com> NNTP-Posting-Host: 213-99-68-16.uc.nombres.ttd.es Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1407507.y0tfPnE92U" Content-Transfer-Encoding: 7Bit User-Agent: KNode/0.6.1