Pelles C Temperature

This is a discussion on Pelles C Temperature within the C Programming forums, part of the General Programming Boards category; Can anyone give me the code to make pelles C read numbers from a file, and then write to another ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Question Pelles C Temperature

    Can anyone give me the code to make pelles C read numbers from a file, and then write to another file the average, high, and low temperatures, in that order.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    I daresay yes. What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2
    #include <stdlib.h>
    #include<math.h>
    #include<stdio.h>
    #include<string.h>
    #define inp_file "c:/code/temp/temps.txt"
    #define out_file "c:/code/temp/averages.txt"
    #define debug 1
    int main(void) {
    FILE *inp, *out;
    double temp, average, high, low, input;
    inp = fopen(inp_file,"r");
    out = fopen(out_file,"w");
    if (debug) {
    if (inp==NULL || out == NULL) {
    printf("File does not exist\n");
    return(0); } }
    while (fscanf(input,"%d",&temp) != EOF) {
    printf("%s %lf\n",temp);
    fprintf(out,"%s%lf\n",temp); }
    fclose(inp);
    fclose(out);
    return(0);}


    this is my code, but its not working and I cant quite figure out why.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    Read this -> << !! Posting Code? Read this First !! >>

    Then post your code again, this time using code tags to preserve some sense of indentation.

    Though from editing your post, I see that it doesn't have any indentation to begin with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    1) You expect temp to hold a double, yet your fscanf() is formatted to read int.
    2) printf("%s %lf\n",temp); expects two parameters. Same with the next fprintf statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opinion on C99 ver. of Pelles C IDE?
    By Adak in forum C Programming
    Replies: 0
    Last Post: 03-13-2009, 08:27 PM
  2. Motherboard Temperature
    By MK4554 in forum Windows Programming
    Replies: 1
    Last Post: 07-18-2006, 11:51 AM
  3. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 02:15 PM
  4. read the CPU temperature
    By BianConiglio in forum Windows Programming
    Replies: 2
    Last Post: 05-19-2004, 12:41 PM
  5. functions ??? help
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2001, 03:33 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21