Thread: storing ppm data into arrays need help

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    6

    storing ppm data into arrays need help

    im doing this program where i analyze colors in a ppm file


    now im having a hard time storing the data into arrays in this order


    P3
    600 339
    255
    44 5 8
    44 5 8
    43 4 7
    42 3 6
    42 3 4
    44 5 6
    ...






    so far i tried using fscanf()




    -----------------------------------------------------------



    Code:
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    
    
    #define DEBUG true
    #define CHECK true
    
    
    #define C_LIMIT 3
    
    
    
    
    int main()
    {
       int operand_1[99][C_LIMIT];
    
    
    
    
       int row1 = 0;
       int column1;
       int input_x;
    
    
       int row2 = 0;
       int column2 = 0;
       int input_y;
    
    
       int row3;
       int column3;
    
    
    
    
       int clear;
       int clear1 = 0;
       int clear2 = 0;
       int clear3 = 0;
       int clear4 = 0;
       int until;
       int count = 0;
    
    
       int zeros = 0;
       int num;
       int reverse;
       int original;
    
    
       int reverse_sum;
    
    
       int organize_1;
       int result;
       int organize_2;
    
    
       int debug;
       int str1, str2, str3;
       int year;
       FILE *fp;
    
    
       fp = fopen ("n44f - Copy.ppm", "r");
    
    
    
    
       //rewind(fp);
    
    
    
    
    
    
    
    
             do
      {
        for (column1=0; column1 < 3; column1++)
          {
            fscanf(fp, "%d", &num);
              operand_1[row1][column1] = num;
          }
          column1=0;
          row1++;
       }while(operand_1[row1][column1] != EOF);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
       for(row2 = 0; row2 <= row1;){
    
    
             if(row2 != row1){
                if(column2!=3){
               printf("row %d  column %d  |%d|\t",row2,column2,operand_1[row2][column2]);
               column2++;
             }
             else if((column2==3)){
                    column2=0;
                    ++row2;
                    printf("\n");
    
    
             }
    
    
    
    
             }
    
    
             else{
                        for(;column2 < column1;){
                        printf("row %d  column %d  |%d|\t",row2,column2,operand_1[row2][column2]);
                        column2++;
                    }
             break;
    
    
             }
    
    
             }
    printf("\n");
    if(DEBUG) printf("[DEBUG] column1 = %d\n", column1);
    if(DEBUG) printf("[DEBUG] row1 = %d\n", row1);
    if(DEBUG) printf("[DEBUG] column2 = %d\n", column2);
    if(DEBUG) printf("[DEBUG] row2 = %d\n", row2);
    if(DEBUG) printf("[DEBUG] count = %d\n", count);
    if(DEBUG) printf("[DEBUG] zeros = %d\n", zeros);
    if(DEBUG) printf("[DEBUG] clear = %d\n", clear);
    if(DEBUG) printf("[DEBUG] until = %d\n", until);
    if(DEBUG) printf("[DEBUG] clear2 = %d\n", clear2);
    if(DEBUG) printf("[DEBUG] clear4 = %d\n", clear4);
    
    
    
    
    
    
    
    
    
    
       fclose(fp);
    
    
       return(0);
    }
    ------------------------------------------




    and then i tried using fgetc()






    ------------------------------------------




    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    
    
    #define DEBUG true
    #define CHECK true
    
    
    #define C_LIMIT 3
    
    
    
    
    int main()
    {
       int operand_1[99][C_LIMIT];
    
    
    
    
       int row1;
       int column1;
       int input_x;
    
    
       int row2 = 0;
       int column2 = 0;
       int input_y;
    
    
       int row3;
       int column3;
    
    
    
    
       int clear;
       int clear1 = 0;
       int clear2 = 0;
       int clear3 = 0;
       int clear4 = 0;
       int until;
       int count = 0;
    
    
       int zeros = 0;
       int reverse;
       int original;
    
    
       int reverse_sum;
    
    
       int organize_1;
       int result;
       int organize_2;
    
    
       int debug;
       int str1, str2, str3;
       int year;
       FILE *fp;
    
    
       fp = fopen ("n44f - Copy.ppm", "r");
    
    
    
    
       //rewind(fp);
    
    
    
    
    
    
    
    
    
    
             for (column1 = 0, row1 = 0;(input_x=fgetc(fp)) != EOF;){
    
    
    
    
             if(column1!=3){
    
    
                if(input_x!='\n'){
    
    
                if(CHECK) printf("[CHECK] pass 1\n");
                count++;
    
    
                operand_1[row1][column1]=input_x;
                zeros++;
                if(DEBUG) printf("[DEBUG] row1 = %d  column1 = %d\n", row1, column1);
    
    
    
    
    
    
             }
    
    
    
    
             else if(input_x!=' '){
                    
                
                
             }
             
             else{
                    count++;
    
    
                    zeros++;
                if(CHECK) printf("[CHECK] didnt pass 2\n");
                clear2++;
    
    
                   column1--;
    
    
    
    
    
    
    
    
    
    
    
    
             }
    
    
    
    
    ++column1;
    
    
             }
             else{
    
    
                    if(input_x!='\n' && input_x!=' '){
                            count++;
    
    
                            if(CHECK) printf("[CHECK] pass 3\n");
                            column1=0;
                    ++row1;
                operand_1[row1][column1]=input_x;
                zeros++;
                if(DEBUG) printf("[DEBUG] row1 = %d  column1 = %d\n", row1, column1);
                column1++;
    
    
    
    
                    }
                    else{
                            count++;
                            if(CHECK) printf("[CHECK] didnt pass (4)\n");
                            clear4++;
                            ++row1;
                            zeros++;
                            column1=0;
                     }
    
    
    
    
    
    
             }
    
    
    
    
    
    
             }
    
    
    
    
    
    
    
    
       for(row2 = 0; row2 <= row1;){
    
    
             if(row2 != row1){
                if(column2!=3){
               printf("row %d  column %d  |%c|\t",row2,column2,operand_1[row2][column2]);
               column2++;
             }
             else if((column2==3)){
                    column2=0;
                    ++row2;
                    printf("\n");
    
    
             }
    
    
    
    
             }
    
    
             else{
                        for(;column2 < column1;){
                        printf("row %d  column %d  |%c|\t",row2,column2,operand_1[row2][column2]);
                        column2++;
                    }
             break;
    
    
             }
    
    
             }
    printf("\n");
    if(DEBUG) printf("[DEBUG] column1 = %d\n", column1);
    if(DEBUG) printf("[DEBUG] row1 = %d\n", row1);
    if(DEBUG) printf("[DEBUG] column2 = %d\n", column2);
    if(DEBUG) printf("[DEBUG] row2 = %d\n", row2);
    if(DEBUG) printf("[DEBUG] count = %d\n", count);
    if(DEBUG) printf("[DEBUG] zeros = %d\n", zeros);
    if(DEBUG) printf("[DEBUG] clear = %d\n", clear);
    if(DEBUG) printf("[DEBUG] until = %d\n", until);
    if(DEBUG) printf("[DEBUG] clear2 = %d\n", clear2);
    if(DEBUG) printf("[DEBUG] clear4 = %d\n", clear4);
    
    
    
    
    
    
    
    
    
    
       fclose(fp);
    
    
       return(0);
    }
    -----------------------------------------------------


    im still having a hard time storing them the way i wanted


    the second method i tried stored them in this order


    P 3 6
    0 0 3
    3 9 2
    5 5 4
    4 5 8
    4 4 5
    8 4 3
    ...


    i then realized that the order that the second method gave me will make it very hard for me to calculate the RGBs.

    because they will be calculated like wise..

    P3
    600 339
    255
    44 5 8 = sum
    44 5 8 = sum
    43 4 7 = sum
    42 3 6 = sum

    42 3 4 = sum
    44 5 6 = sum
    ...

    but that isn't the issue right now..


    please excuse my messy program i need help


    thanks

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    please excuse my messy program i need help
    It is rude to ask people to look through your code when you don't use proper indentation. You should fix it and repost it.

    but that isn't the issue right now
    What is your code meant to do? What is it doing?

    At a glance, you are not checking to see if fp is opening.

    Have a look at this tutorial - It should help Intro to File Input/Output in C
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    6
    the program is suppose to collect data from a .ppm image file, pixal data as in R G B.

    and im suppose to make a program that can pinpoin the darkest pixals and output them to the screen.

    the math is simple im just having a hard time storing them correctly


    Code:
    
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    
    
    #define DEBUG true
    #define CHECK true
    
    
    #define C_LIMIT 3
    
    
    
    
    int main()
    {
       int second[999][C_LIMIT];
    
    
    
    
       int row1 = 0;
       int column1;
       int input_x;
    
    
       int row2 = 0;
       int column2 = 0;
       int input_y;
    
    
       int row3;
       int column3;
    
    
    
    
       int clear;
       int clear1 = 0;
       int clear2 = 0;
       int clear3 = 0;
       int clear4 = 0;
       int until;
       int count = 0;
    
    
       int zeros = 0;
       int num;
    
    
       FILE *fp;
    
    
       fp = fopen ("n44f - Copy.ppm", "r"); //<<<<<<< the file opens
    
    
    
    
    
    
    
    
    
    
    
    
    //-------------------------=stores data into arrays=-----------------------------------
    
    
             for(row1 = 0; row1<3 ;row1++)
      {
    
    
        for (column1=0; column1 < 3; )
          {
    
    
              if(num!=EOF){
                fscanf(fp, "%d", &num);
                 second[row1][column1]=num;
              column1++;
              }
              else
                break;
          }
          column1=0;
    
    
      }
    
    
    
    
    
    
    
    
    
    
    
    
    //--------------------=reads and prints arrays for debug=----------------------------
    
    
       for(row2 = 0; row2 <= row1;){
    
    
    		 if(row2 != row1){
                if(column2!=3){
               printf("row %d  column %d  |%d|\t",row2,column2,second[row2][column2]);
               column2++;
             }
             else if((column2==3)){
                    column2=0;
                    ++row2;
                    printf("\n");
    
    
             }
    
    
    
    
    		 }
    
    
    		 else{
                        for(;column2 < column1;){
                        printf("row %d  column %d  |%d|\t",row2,column2,second[row2][column2]);
                        column2++;
                    }
             break;
    
    
    		 }
    
    
    		 }
    
    
    //------------------------------------------------------------------------------------------
    
    
    printf("\n");
    if(DEBUG) printf("[DEBUG] column1 = %d\n", column1);
    if(DEBUG) printf("[DEBUG] row1 = %d\n", row1);
    if(DEBUG) printf("[DEBUG] column2 = %d\n", column2);
    if(DEBUG) printf("[DEBUG] row2 = %d\n", row2);
    if(DEBUG) printf("[DEBUG] count = %d\n", count);
    if(DEBUG) printf("[DEBUG] zeros = %d\n", zeros);
    if(DEBUG) printf("[DEBUG] clear = %d\n", clear);
    if(DEBUG) printf("[DEBUG] until = %d\n", until);
    if(DEBUG) printf("[DEBUG] clear2 = %d\n", clear2);
    if(DEBUG) printf("[DEBUG] clear4 = %d\n", clear4);
    
    
    
    
    
    
    
    
    
    
       fclose(fp);
    
    
       return(0);
    }
    now so far the only issue with this is that im unable to store the whole .ppm file into the arrays because whenever i try cmd crashes for some reason

    is here a way where i can also read a file starting from for example the second line but not the first?
    Last edited by Majid Fahad; 03-30-2014 at 12:45 AM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Please read the info on this link fscanf - C++ Reference

    Code:
    fscanf(fp, "%d", &num);
    Why do you think the variable num will get the value EOF in it?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Mar 2014
    Posts
    6
    Quote Originally Posted by stahta01 View Post
    Please read the info on this link fscanf - C++ Reference

    Code:
    fscanf(fp, "%d", &num);
    Why do you think the variable num will get the value EOF in it?

    Tim S.
    youre right EOF only works with chars...

    so how do i tell it to stop reading integers since it already skips white space?

  6. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    The fscanf function itself returns EOF, not in the variable "num"

    i.e.
    Code:
    int apple;
    int banana;
    
    apple = fscanf(fp, "%d", &banana);
    C99 Draft, 7.19.6.2 The fscanf function
    Returns

    #18

    The fscanf function returns the value of the macro EOF if an input failure occurs before any conversion. Otherwise, the function returns the number of input items assigned, which can be fewer than provided for, or even zero, in the event of an early matching failure.
    There are lots of examples out there on fscanf: Have a look at how they use fscanf in a while() loop
    Last edited by Click_here; 03-30-2014 at 03:39 AM.
    Fact - Beethoven wrote his first symphony in C

  7. #7
    Registered User
    Join Date
    Mar 2014
    Posts
    6
    i have updated my code and im having problems with it


    the ppm file looks like this..

    P3
    600 339
    255
    [1 2 3] <------------------------------------------------------------------------------|
    4 5 6 |
    7 8 9 |
    .. |
    |
    |
    the issue is now, is that for some reason that whole line is being skipped and | not being stored. >-------------------------------------------------------------------|

    run the program and you'll understand





    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    
    
    #define DEBUG true
    #define CHECK true
    
    
    
    
    
    
    FILE *fp;
    int main(void){
    
    
    fp = fopen("n44f - Copy.ppm", "r");
    int line_one[2];
    int pixels[300][3];
    int height;
    int width;
    int max_color;
    int enter;
    int column1 = 0;
    int row1 = 0;
    int loop;
    int count = 0;
    int check = 0;
    
    
    
    
    //---this part reads the first 4 integers in the .ppm file and stores them---
    
    
    fscanf(fp, "%s %d %d %d", line_one, &height, &width, &max_color);  
    
    
    //---this part reads the rest of the .ppm file and stores them all in the pixels[][] array---
    
    
    
    while(loop!=EOF){
        if(CHECK)printf("[CHECK] pass [1]\n");
        fscanf(fp, "%d %d %d",&pixels[row1][0], &pixels[row1][1], &pixels[row1][2]);
        loop = fscanf(fp, "%d %d %d",&pixels[row1][0], &pixels[row1][1], &pixels[row1][2]);
        row1++;
        count++;
    }
    
    
    //---this part debugs and checks if the arrays are stored properly---
    
    while(check<count){
    
    
        if(DEBUG)printf("[DEBUG] pixels[%d][0] = |%d|, pixels[%d][1] = |%d|, pixels[%d][2] = |%d|\n",check, pixels[check][0], check, pixels[check][1], check, pixels[check][2]);
    
    
    
    
        check++;
    }//while(loop!=EOF);
    
    
    
    
    
    
    
    
    
    
    printf("line_one = %s\n", line_one);
    printf("height = %d\n", height);
    printf("width = %d\n", width);
    printf("max_color = %d\n", max_color);
    //printf("enter = %d\n", enter);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }

    for those who don't know what a .ppm file is

    its a txt file that has data that looks exactly like this

    P3
    600 339
    255
    44 5 8
    44 5 8
    43 4 7
    42 3 6
    42 3 4
    44 5 6
    46 6 7
    ..

    the data is then translated into an image
    so it works exactly like a txt. file
    Last edited by Majid Fahad; 04-05-2014 at 02:42 PM.

  8. #8
    Registered User
    Join Date
    Mar 2014
    Posts
    6
    and finally

    Code:
    
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    
    
    #define DEBUG false
    #define CHECK false
    
    
    #define C_LIMIT 3
    
    
    FILE *fp;
    int main(void){
    
    
    fp = fopen("n44f - Copy.ppm", "r");
    
    
    int line_one[2];
    int pixels[173567][3];    <--- because if this im getting segmentation fault
    int height;
    int width;
    int max_color;
    int enter;
    int column1 = 0;
    int row1 = 0;
    int loop;
    int count = 0;
    int check = 0;
    int one;
    int two;
    int three;
    
    
    
    
    
    
    fscanf(fp, "%s", line_one);
    fscanf(fp, "%d %d", &height, &width);
    fscanf(fp, "%d",&max_color);
    
    
    
    
    
    
    for (row1 = 0;loop != EOF; row1++) {
      for (column1 = 0; column1 < 3; ++column1) {
        loop = fscanf(fp, "%d", &enter);
        pixels[row1][column1] = enter;
      }
    }
    
    
    
    
    printf("line_one = %s\n", line_one);
    printf("height = %d\n", height);
    printf("width = %d\n", width);
    printf("max_color = %d\n", max_color);
    
    
    
    
    if(DEBUG){
    for(count = 0;count<row1-1;count++){
    
    
        if(DEBUG)printf("[DEBUG] [%d][0] = |%d|, [%d][1] = |%d|, [%d][2] = |%d|\n", count,pixels[count][0],count,pixels[count][1],count,pixels[count][2]);
    
    
    }
    }
    
    
    if(DEBUG)printf("[DEBUG] row1 = %d\n", row1);
    if(DEBUG)printf("[DEBUG] count = %d\n", count);
    printf("Length: %d", sizeof(pixels));
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    i need a way to store up to 300000 rows in a 2d array

  9. #9
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    Looks as if you have hit the stack limit.

    You could either use malloc() to allocate memory on the heap or declare the array static and memory will be made available in the data
    segment.

    The latter is probably the easiest solution.
    Last edited by gemera; 04-05-2014 at 05:58 PM.

  10. #10
    Registered User
    Join Date
    Mar 2014
    Posts
    6
    the project description is..


    Astronomers have come to you with a problem - they want you to write a program to nd
    the darkest points of the sky from an image taken from one of their telescopes. After careful
    analysis of their images you determined that all of them are rather \noisy", meaning that
    they contain a signicant number of pixels that are distorted in some manner. As a result of
    this absolute darkness (total blackness) rarely occurs in any of their images. Despite these
    problems, however, you were able to come up with a simple but eective scheme to nd the
    darkest points in these images. After nding the darkest point (the point closest to total
    blackness), you discovered that all points within 30% of this point (as dened below) can
    also be considered a signicantly dark point in the image.
    Write a C program that inputs a PPM image le (as dened below) of up to 500,000 RGB
    points, with each point dened by 3 integer values (an RGB triplet) in the range of 0-255
    inclusive, where (0,0,0) equals black and (255,255,255) is white. We will dene a pixel's
    darkness value DV as the sum of its R, G, and B values, with absolute black therefore
    having DV = 0. Your program should rst nd the darkest point in the image, then output
    the coordinates (in order top-to-bottom, left-to-right, with the row rst followed by the
    column) of all pixels that have a DV within (i.e. up to and including) 30% of this value.
    For example, if DV = 29 for the darkest point in an image, you should report the locations
    of all pixels with a DV up to and including 38. When reporting the location of your dark
    pixels, assume the upper left corner of the image is location 1, 1. If you need to convert
    from a
    oat to an integer, your program should round o using the math.h function rintf.
    You need to input the image le name from the command line as demonstrated in class (see
    the sample run below). Also you should only input the data le once. All of your output
    should match the sample run exactly (with the exception of the rst line). If the input le
    does not exist or if it contains an illegal number of points, report an error and immediately
    exit the program. You may assume that each triplet is complete (i.e. if a pixel is dened at
    all, 3 values will be contained in the le for that pixel).


    this is my latest code update

    Code:
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    
    
    #define DEBUG false
    #define CHECK false
    
    
    #define NROWS 999999
    
    
    FILE *fp;
    int main(void){
    
    
    fp = fopen("n44f - Copy.ppm", "r");
    
    
    int line_one[2];
    
    
    int **pix;
    int *sum;
    int height;
    int width;
    int max_color;
    int enter;
    int column1 = 0;
    int row1 = 0;
    int loop;
    int count = 0;
    int check = 0;
    int smallest;
    int DV;
    int three;
    int i;
    
    
    
    
    //------pix array------
    pix = malloc(NROWS * sizeof(int *));
        if(pix == NULL)
            {
            fprintf(stderr, "out of memory\n");
            return 0;
            }
        for(i = 0; i < NROWS; i++)
            {
            pix[i] = malloc(3 * sizeof(int));
            if(pix[i] == NULL)
                {
                fprintf(stderr, "out of memory\n");
                return 0;
                }
            }
    
    //------storing data, 1st 4 lines----
    
    
    fscanf(fp, "%s", line_one);
    fscanf(fp, "%d %d", &height, &width);
    fscanf(fp, "%d",&max_color);
    
    
    
    
    //-----storing the pixels into pix array----
    for (row1 = 0;loop != EOF; ) {
      for (column1 = 0; column1 < 3; ++column1) {
        loop = fscanf(fp, "%d", &enter);
        pix[row1][column1] = enter;
      }
      row1++;
      check++;
    }
    
    
    
    
    printf("line_one = %s\n", line_one);
    printf("height = %d\n", height);
    printf("width = %d\n", width);
    printf("max_color = %d\n", max_color);
    
    
    
    
    if(DEBUG){
    for(count = 0;count<row1-2;count++){
    
    
        if(DEBUG)printf("[DEBUG] [%d][0] = |%d|, [%d][1] = |%d|, [%d][2] = |%d|\n", count,pix[count][0],count,pix[count][1],count,pix[count][2]);
    
    
    }
    }
    
    
    //----sum array------
    sum = malloc(NROWS * sizeof(int *));
    
    
    //----summing the pixels and storing them into sum array---
    for(loop = 0;loop < row1-1;loop++){
       sum[loop] = pix[loop][0] + pix[loop][1] + pix[loop][2];
    
    
       if(sum[loop]<sum[loop-1])
          smallest = sum[loop];
    
    
    }
    //-------finding the values that are 30% of the 'smallest' and lower
    DV = round((float)((smallest*0.3)+smallest));
    for(loop = 0;loop < row1-1;loop++){
       if(sum[loop]<=DV){
          printf("[%d]\n",sum[loop]);
       }
    
    
    }
    
    
    if(!DEBUG)printf("[DEBUG] smallest = %d\n",smallest);
    if(!DEBUG)printf("[DEBUG] DV = %d\n",DV);
    if(!DEBUG)printf("[DEBUG][sum] [0]=|%d|, [1]=|%d|, [2]=|%d|\n",sum[0],sum[1],sum[2]);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    if(!DEBUG)printf("[DEBUG] row1 = %d\n", row1);
    if(!DEBUG)printf("[DEBUG] [0][0]=|%d|, [0][1]=|%d|, [0][2]=|%d|\n",pix[0][0],pix[0][1],pix[0][2]);
    if(!DEBUG)printf("[DEBUG] [%d][0]=|%d|, [%d][1]=|%d|, [%d][2]=|%d|\n",row1-2,pix[row1-2][0],row1-2,pix[row1-2][1],row1-2,pix[row1-2][2]);
    
    
    if(!DEBUG)printf("[DEBUG] check = %d\n", check);
    printf("Length: %d\n", sizeof(pix));
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    for(i = 0; i < NROWS; i++)
            free(pix[i]);
    free(pix);
    
    
    
    
    free(sum);
    
    
    }


    am i missing anything???

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I suggest re-formatting your code and turning on warnings.

    Code:
    -------------- Build: Debug in testppm (compiler: GNU GCC Compiler)---------------
    
    mingw32-gcc.exe -Wall -g -Wmissing-include-dirs -Wfatal-errors -Wno-unused-local-typedefs -Wno-attributes  -c E:\OpenSourceCode\Test\testppm\main.c -o obj\Debug\main.o
    E:\OpenSourceCode\Test\testppm\main.c: In function 'main':
    E:\OpenSourceCode\Test\testppm\main.c:65:1: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'int *' [-Wformat=]
     fscanf(fp, "%s", line_one);
     ^
    E:\OpenSourceCode\Test\testppm\main.c:85:1: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int *' [-Wformat=]
     printf("line_one = %s\n", line_one);
     ^
    E:\OpenSourceCode\Test\testppm\main.c:39:5: warning: unused variable 'three' [-Wunused-variable]
     int three;
         ^
    E:\OpenSourceCode\Test\testppm\main.c:215:1: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I can't Storing data to use later
    By errigour in forum C Programming
    Replies: 11
    Last Post: 08-16-2011, 06:22 AM
  2. Problem Storing Data in arrays.
    By Laythe in forum C Programming
    Replies: 21
    Last Post: 03-24-2011, 11:19 AM
  3. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  4. Storing # from Data File in Arrays?
    By dakarn in forum C Programming
    Replies: 7
    Last Post: 11-13-2008, 09:15 PM
  5. Replies: 3
    Last Post: 02-26-2008, 02:12 PM

Tags for this Thread