Thread: Pelles C Temperature

  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
    28,413
    I daresay yes. What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    39,659
    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.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    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, 07:27 PM
  2. Motherboard Temperature
    By MK4554 in forum Windows Programming
    Replies: 1
    Last Post: 07-18-2006, 10:51 AM
  3. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  4. read the CPU temperature
    By BianConiglio in forum Windows Programming
    Replies: 2
    Last Post: 05-19-2004, 11:41 AM
  5. functions ??? help
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2001, 02:33 AM

Tags for this Thread