Hello, how can I place the ñ after age?,and will not let me put another name example "Diego Alex"

/* Autor:Diego
Definicion;Primer algoritmo*/

#include <stdio.h>
#include <conio.h>

int main () {
char nombre[30];
int edad;
printf ("Escribe tu nombre : ");
scanf ("%s",&nombre);
printf ("Escribe tu edad : ");
scanf ("%d",&edad);
printf ("Hola %s tu edad es %d ",nombre, edad);
getch ();
return 0;
}
Last edited on
Hello, how can I place the ñ after age?
What do you mean? Something like that:

printf ("\nHola %s tu edad es %d ",nombre, edad); // \n -> extra new line

See this:
http://www.cplusplus.com/reference/cstdio/scanf/?kw=scanf

Remove the address operator in front of nombre:

scanf ("%s",&nombre);

and will not let me put another name example "Diego Alex"
scanf stops at the first whitespace after the relevant expression. To get an expression that includes spaces use gets():

http://www.cplusplus.com/reference/cstdio/gets/
about gets()
cplusplus wrote:
The most recent revision of the C standard (2011) has definitively removed this function from its specification.
The function is deprecated in C++ (as of 2011 standard, which follows C99+TC3).
man wrote:
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.
cppreference wrote:
The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear on stdin). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard.


So don't use gets()
Topic archived. No new replies allowed.