Crear archivo formula general AYUDA PORFAVOR
Publicado por Giovanni (4 intervenciones) el 18/03/2019 01:56:07
BUEN DIA ESTOY HACIENDO UN PROGRAMA QUE RESUELVE LA ECUACION GENERAL.
PRIMERO LEE LOS VALORES DE UN ARCHIVO TXT COMO CARACTERES Y LOS CONVIERTE A NUMEROS, SEGUIDAMENTE HAGO EL PROCEDIMIENTO.
EL PROBLEMA ES QUE QUIERO IMRPIMIR LOS DISTINTOS RESULTADOS EN UN ARCHIVO TXT PERO ME MARCA UN ERROR.
" error 139 - Argument no 1 of 'printf' must be of type '<ptr>const char', n " ESE ES EL ERROR
EL CODIGO ES EL SIGUIENTE
PRIMERO LEE LOS VALORES DE UN ARCHIVO TXT COMO CARACTERES Y LOS CONVIERTE A NUMEROS, SEGUIDAMENTE HAGO EL PROCEDIMIENTO.
EL PROBLEMA ES QUE QUIERO IMRPIMIR LOS DISTINTOS RESULTADOS EN UN ARCHIVO TXT PERO ME MARCA UN ERROR.
" error 139 - Argument no 1 of 'printf' must be of type '<ptr>const char', n " ESE ES EL ERROR
EL CODIGO ES EL SIGUIENTE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//Primero el usuario debe ingresar los coeficientes en el archivo de entrada
//para posteriormente ejecutar el programa.
#include<stdio.h>//Biblioteca principale
#include<stdlib.h>//Biblioteca principale
#include<math.h>//Biblioteca para operaciones matematicas
int main()
{
char linea[5];//Vector en donde guardaremos los datos de entrada
float a, b, c, x1, x2,deter;// Declaracion de variables
FILE *archivo; //Fichero para abrir leer el archivo
archivo=fopen("general.txt", "w+");//Codigo para abrir el archivo para lectura y escritura
fscanf(archivo, " %s", linea);//Se lee el T.cuadratico del archivo
a=atoi(linea);//Se transforma de caracter a numero
fscanf(archivo, "%s", linea);//Se lee el T.lineal del archivo
b=atoi(linea);//Se transforma de caracter a numero
fscanf(archivo, "%s", linea);//Se lee el T. independiente del archivo
c=atoi(linea);//Se transforma de caracter a numero
printf("\n Los datos leidos del archivo son: ");
printf("\n %f", a); //Se imprime los datos en pantalla
printf("\n %f", b); //Se imprime los datos en pantalla
printf("\n %f", c);//Se imprimelos datos en pantalla
deter=(pow(b,2)-(4*a*c));//Determinante para conocer los distintos casos
if(deter==0)//Primer caso
{x1= -b/(2*a);
fprintf(*archivo,"\n\n Solo hay una solucion: %f",x1);}
else if(deter<0)//Segundo caso
{fprintf(*archivo,"\n\n No existen soluciones reales, solo imaginarias");}
else //Tercer caso
{x1=(-b+sqrt(deter))/(2*a);
x2=(-b-sqrt(deter))/(2*a);
fprintf(*archivo,"\n\n Las soluciones son: %f y %f",x1,x2);}
fclose (archivo);//Se cierra el archivo
return 0;
}
Valora esta pregunta


0