Por que no me formatea sprintf ??
Publicado por Adrian Judas (4 intervenciones) el 01/03/2025 16:15:29
Hola, tengo el siguiente codigo:
#include <iostream>
#include <stdio.h>
#include <tchar.h>
using namespace std;
void muestraNumero();
int _tmain(int argc, _TCHAR* argv[])
{
muestraNumero();
}
//----------------------------------------------------------------------------
void muestraNumero()
{
short int numero;
char linea[40], a;
cout << "Introduzca un numero: ";
cin >> numero;
sprintf(linea,"Numero %d en Hexadecimal es: %x", numero, numero);
cout << linea << endl;
sprintf(linea,"Numero %d en Octal es: %o", numero, numero);
cout << linea << endl;
cin >> a;
}
//----------------------------------------------------------------------------
Y el sprintf no me esta funcionando, me sale en %x y %o como si fuera %d
#include <iostream>
#include <stdio.h>
#include <tchar.h>
using namespace std;
void muestraNumero();
int _tmain(int argc, _TCHAR* argv[])
{
muestraNumero();
}
//----------------------------------------------------------------------------
void muestraNumero()
{
short int numero;
char linea[40], a;
cout << "Introduzca un numero: ";
cin >> numero;
sprintf(linea,"Numero %d en Hexadecimal es: %x", numero, numero);
cout << linea << endl;
sprintf(linea,"Numero %d en Octal es: %o", numero, numero);
cout << linea << endl;
cin >> a;
}
//----------------------------------------------------------------------------
Y el sprintf no me esta funcionando, me sale en %x y %o como si fuera %d
Valora esta pregunta


0