-
-
Save parzibyte/eeb7340819835ad264a27c70c07fed6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://parzibyte.me/blog | |
*/ | |
#include <stdio.h> | |
#include <string.h> // Para strlen | |
#define MAXIMA_LONGITUD_CADENA 50 | |
void consumirNuevaLinea(void) | |
{ | |
int c; | |
do | |
{ | |
c = getchar(); | |
} while (c != EOF && c != '\n'); | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
int edad; | |
printf("Escribe tu edad: "); | |
scanf("%d", &edad); | |
// Consumir nueva línea | |
consumirNuevaLinea(); | |
char nombre[MAXIMA_LONGITUD_CADENA]; | |
printf("Ingresa tu nombre completo: "); | |
fgets(nombre, MAXIMA_LONGITUD_CADENA, stdin); | |
// Remover salto de línea | |
if ((strlen(nombre) > 0) && (nombre[strlen(nombre) - 1] == '\n')) | |
{ | |
nombre[strlen(nombre) - 1] = '\0'; | |
} | |
printf("Tu nombre es %s", nombre); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment