I want to print a character but it has a string inside... I get the error:
125 8 [Warning] assignment makes integer from pointer without a cast
The problem is found almost at the last, where it says:
//Funciones para salida de datos
//Salida de suma
The code:
#include<stdio.h>
#include<locale.h>
#include<ctype.h>
#include<math.h>
//Prototipo - Funcion
int suma(int, int);
int resto(int, int);
int multiplicacion(int, int);
float divicion(int, int);
int resio(int, int);
int pote(int, int);
float raiz(int, int);
//Prototipo para salida de datos
char salidaSuma();
//Función Principal
int main(){
setlocale(LC_CTYPE,"spanish");
int n1, n2, potencia, sum, resta, multi, residuo;
float divi, raz;
n1 = 36;
n2 = 2;
printf("\n");
sum = suma(n1, n2);
resta = resto(n1, n2);
multi = multiplicacion(n1, n2);
divi = divicion(n1, n2);
residuo = resi(n1, n2);
potencia = pote(n1, n2);
raz = raiz(n1, n2);
printf("La suma de los numeros es: %i\n",sum);
printf("La resta de los numeros es: %i\n",resta);
printf("La multiplicacion de los numeros es: %i\n",multi);
printf("La divicion de los numeros es: %.2f\n",divi);
printf("La residuo de los numeros es: %i\n",residuo);
printf("La potencia de los numeros es: %i\n",potencia);
printf("La raiz de los numeros es: %.2f\n",raz);
printf("\n");
printf("%c %i",salidaSuma(),sum);
return 0;
}
//Funciones
//1.1 ingresar num1
int ingresarNum1(){
int num1;
printf("Ingresar el primer valor: ");
scanf("%i",&num1);
return num1;
}
// 1.2 Ingresar num2
int ingresarNum2(){
int num2;
printf("Ingresar el segundo valor: ");
scanf("%f",&num2);
return num2;
}
//2 suma
int suma(int num1, int num2){
int resultado;
resultado = num1+num2;
return resultado;
}
//3 resta
int resto(int num1, int num2){
int resultado;
resultado = num1 - num2;
return resultado;
}
//4 multiplicacion
int multiplicacion(int num1, int num2){
int resultado;
resultado = num1 * num2;
return resultado;
}
//5 divicion
float divicion(int num1, int num2){
float resultado;
resultado = num1 / num2*1.0;
return resultado;
}
//6 residuo
int resi(int num1, int num2){
int resultado;
resultado = num1%num2;
return resultado;
}
//7 potencia
int pote(int num1, int num2){
int pot;
pot = pow(num1, num2);
return pot;
}
//8 raiz
float raiz(int num1, int num2){
float raz, ind;
ind = 1.0 / num2;
raz = pow(num1, ind);
return raz;
}
//Funciones para salida de datos
//Salida de suma
char salidaSuma(){
char resul;
resul = "La suma de los numeros es: ";
return resul;
}
A type
char
can only store one character, since a variable of this type will only occupy 1 byte, which allows it to store 256 different values.To handle character strings you need a pointer to
char
:On the other hand, the code that prints the output of this function is also wrong, since what you are going to print is a string of characters:
Even so, this function is totally meaningless and useless. It does not provide any kind of improvement or advantage over the following code:
what I see is that you want to save a string (string of several characters) in a char that you can only save a single letter or character options or you change char result for some vector to be able to contain as many letters (char) in line 124 another option would be skip line 130 resul = "The sum of the numbers is: "; and directly show by means of a scanf in the return