Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Image decoder with c

Options
  • 17-11-2016 4:40pm
    #1
    Registered Users Posts: 35


    Hi people,

    I had this working when i left a class room i came home and i'm getting endless errors, I'm new to this and i'm struggling!!

    Any help would be much appreciated!

    Regards,
    Mark

    *********************************************************

    #include <stdio.h>
    #include <stdlib.h>

    int calcSum (int rows, int colums, int pixels[rows][colums] );
    //void getNumbers (int * pixels);
    //void displayResults()

    int main()
    {

    int i, j;
    int f_type;
    int rows;
    int colums;
    int range;
    int sum = 0;
    float average;
    int max;


    // get numbers
    FILE *input_fptr;

    /* Open file for reading */
    input_fptr = fopen("image1.pgm", "r");

    if( input_fptr != NULL )
    {
    fscanf(input_fptr, "%d", & f_type);
    fscanf(input_fptr, "%d", & rows);
    fscanf(input_fptr, "%d", & colums);
    fscanf(input_fptr, "%d", & range);

    printf( "f_type = %d\n", f_type);
    printf( "rows = %d\n", rows);
    printf( "colums = %d\n", colums);
    printf( "range = %d\n", range);

    int pixels[rows][colums];

    for( i=0; i < rows; i++)
    {
    for( j=0; j < colums; j++)
    {
    //reads fuile to array and then prints it out
    fscanf(input_fptr, "%d", & pixels[j]);
    // printf( "x[%d] [%d] = %d\n", i, j, pixels[j]);
    }
    }
    fclose(input_fptr);

    // get numbers end

    //start calcSum
    sum = calcSum (rows, colums, pixels);
    printf("the sum of all pixels --->>%d\n" ,sum);


    //end calcSum


    //calcAverage start
    average = sum/(rows*colums);
    printf("\nAverage of sum--->>%f\n", average);

    max = pixels [0][0];

    for( i=0; i < rows; i++)
    {
    for( j=0; j < colums; j++)
    {
    if (max < pixels[j])
    max = pixels[j];
    }
    }
    printf("the max value --->>%d\n" , max);


    }

    return 0;
    } // end of main


    int calcSum (int rows, int colums, int pixels[rows][colums])
    {

    int sum = 0;
    int i,j;

    for( i=0; i < rows; i++)
    {
    for( j=0; j < colums; j++)
    {
    sum = sum + pixels[j];
    }
    }
    return sum;
    }


Comments

  • Moderators, Technology & Internet Moderators Posts: 11,015 Mod ✭✭✭✭yoyo




  • Registered Users Posts: 7,157 ✭✭✭srsly78


    Format code properly in post, and post your errors. Also post your makefile or detail how you are compiling and running.


  • Registered Users Posts: 35 techintraining


    srsly78 wrote: »
    Format code properly in post, and post your errors. Also post your makefile or detail how you are compiling and running.

    What do you mean?


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    1. Put special code tags in your post so the code is actually readable.
    2. Post the errors you have been getting.
    3. Post details on how you are trying to compile and execute the code. What platform? What compiler?

    Help regarding code tags -> https://www.bbcode.org/examples/?id=15


  • Registered Users Posts: 35 techintraining


    srsly78 wrote: »
    1. Put special code tags in your post so the code is actually readable.
    2. Post the errors you have been getting.
    3. Post details on how you are trying to compile and execute the code. What platform? What compiler?

    Help regarding code tags -> https://www.bbcode.org/examples/?id=15

    Thank 's for the advise I will do that in future


  • Advertisement
Advertisement