char != double.
Don't mix types.
If you read a double, read into a double, NOT a char.
If you assign a double, assign it to a double, NOT a char.
name in the struct is declared as char, so re-think your design!
Printable View
char != double.
Don't mix types.
If you read a double, read into a double, NOT a char.
If you assign a double, assign it to a double, NOT a char.
name in the struct is declared as char, so re-think your design!
Oh, I see what you mean I think.
Like this?:
Code:fprintf(outputFile, "%f -- Reliability %c\n", circuits[n].name);
fprintf(outputFile, "%f -- Cost %c\n", circuits[n].name);
I quoted all of those statements. Also notice in those two lines you have TWO %, but only one argument is passed. Now that's even worse.
Go read up a little on fprintf and the other lines where you assign doubles to char.
Here is what I have now, can anyone help me with inputting the text file?
In the text file, circuit A is denoted by 0, B by 1, C by 2, D by 3, E by 4.Code:#include <stdio.h>
#include <stdlib.h>
#define NUMBER_OF_CIRCUITS 5
typedef struct{
char name;
float reliability;
float cost;
} circuit;
int main()
{
circuit circuits[NUMBER_OF_CIRCUITS];
FILE *inputFile = fopen("circuitreliability.txt", "r");
FILE *outputFile;
float reliability;
float cost;
int n = 0;
int index;
for(n = 0; n < NUMBER_OF_CIRCUITS; n++)
{
circuits[n].circ = 0;
fscanf(inputFile, "%d-%f-%f", &index, &reliability, &cost);
circuits[index].reliability =reliability;
circuits[index].reliability =cost;
fprintf(outputFile, "%d -- Reliability %f\n", circuits[n].name, circuits[n].reliability);
fprintf(outputFile, "%d -- Cost %f\n", circuits[n].name, circuits[n].cost);
}
return (0);
}
The text file's contents is as follows, from what I've been told:
0-.80
1-.75
2-.90
3-.90
4-.70
The struct is necessary in the program.
The program should read the reliability and print it to the screen.
This is all according to the OP.