Thread: Need help on this program!

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Sep 2007
    Posts
    34
    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);

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Sep 2007
    Posts
    34
    Here is what I have now, can anyone help me with inputting the text file?

    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, "&#37;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);
    }
    In the text file, circuit A is denoted by 0, B by 1, C by 2, D by 3, E by 4.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM