Pointer questions

This is a discussion on Pointer questions within the C Programming forums, part of the General Programming Boards category; OK here is my program Code: #include<stdio.h> /* fprint, fscanf, fclose, fopen definitions */ int main(void) { FILE *inp, /* ...

  1. #1
    bignood
    Join Date
    Sep 2005
    Posts
    33

    Pointer questions

    OK here is my program

    Code:
    #include<stdio.h> /* fprint, fscanf, fclose, fopen  definitions */
          
    int main(void)
       
    {
     
      FILE *inp, /* input file pointer */
           *outp; /* output file pointer */
       
      int input_status, /* status of input */
          score, /* current score */ 
          largest, /* largest score */
          smallest; /* smallest score */
       int max=0; /* maximum score */
       int min=0; /* minimum score */
       
       /* open input and output files */
       inp = fopen (  "scores.dat" , "r" );
       outp = fopen (  "results.dat", "w" );
            
       fprintf (outp, "   Scores\n");
       fprintf (outp,  "   ------\n");
    
       input_status = fscanf ( inp, "%d", &score );
    
       max = score;
       min = score;
    
       while ( input_status == 1 ){
            fprintf ( outp, "   %d\n", score);
            if (max < score)
               largest = score;
            if (min > score)
               smallest = score;
    
            max = score++;
            min += score;
            input_status = fscanf ( inp, "%d", &score);
    
    
       }
    
    /*   if ( input_status != 1)
       {
            fscanf ( inp, "%d", &score);
            printf ( "\nError in input of %d", score);
       } */
       if (input_status != 1)
       {
            fscanf ( inp, "%d", &score);
            fprintf( outp, "The highest score is %d\n", max);
            fprintf( outp, "The lowest score is %d\n", min);
       }
       /* closes files */
            
       fclose (inp);
       fclose(outp);
       return(0);
    }
    I want my output to display the largest and the smallest numbers. Now I know that this part
    Code:
            max = score++;
            min += score;
    is wrong. But I don't know what to put to get what I want?

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    well, u have upgrade the max and min value as soon as u get the value which is greater/lesser than score

    Code:
    if (max < score)
               max = score;
            if (min > score)
               min = score;
    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 04:45 AM
  2. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2007, 12:26 AM
  3. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 02:09 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM

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