Thread: What Does This Error Message Mean?

  1. #1
    Registered User
    Join Date
    Dec 2021
    Posts
    34

    What Does This Error Message Mean?

    What Does This Error Message Mean?-error-jpg
    It says to use -> but I've already used ->?
    Last edited by DGB_684; 12-31-2021 at 05:59 AM.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Your image cannot be opened. Please post the code in [CODE] blocks.

  3. #3
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    I've edited the post. It should be visible now.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by DGB_684 View Post
    I've edited the post. It should be visible now.
    Once again you have posted a fuzzy image rather than using [CODE] blocks as is required here.

    Also, you have posted the error messages but not the actual code. Impossible to give you a proper answer. Please post the program code and the error messages in [CODE] blocks.

  5. #5
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    Quote Originally Posted by rstanley View Post
    Once again you have posted a fuzzy image rather than using [CODE] blocks as is required here.

    Also, you have posted the error messages but not the actual code. Impossible to give you a proper answer. Please post the program code and the error messages in [CODE] blocks.
    Its quite long but this is all my code.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    #define maxheight 1080
    #define maxwidth 1920
    #define RGB_COMPONENT_COLOUR 255
    #define pgmtype "P2"
    #define ppmtype "P3"
    
    
    typedef struct
    {
        int red, green, blue;
    } PPMPixel;
    
    
    typedef struct
    {
        int x, y;
        PPMPixel *data;
    } PPMImage;
    
    
    typedef struct 
    {
        int rgb_comp_colour;
        char buff[16];
        char filetype[2];
        int height;
        int width;
    } PPMHead;
    PPMHead head[3];
    
    
    int **Array;
    PPMPixel **RGBArray;
    FILE *fp;
    
    
    void headercheck ()
    {
        fscanf(fp, "%s %d %d %d", head[0].filetype, &head[0].width, &head[0].height, &head[0].rgb_comp_colour);
        printf("%s %d %d %d", head[0].filetype, head[0].width, head[0].height, head[0].rgb_comp_colour);
    
    
        if (head[0].width > maxwidth || head[0].height > maxheight)
        {
            printf("\tInvalid image size. The maximum value of image is 1920x1080.\n");
            printf("\tImage size is %d x %d\n", head[0].width, head[0].height);
        }
        else
        {
            printf("\tImage size is valid\n");
            printf("\tImage size is %d x %d\n", head[0].width, head[0].height);
        }
    
    
        if ((strcmp (head[0].filetype, pgmtype)!=0) && (strcmp (head[0].filetype, ppmtype)!=0))
        {
            printf("\tInvalid filetype\n");
        }
        else
        {
            if(strcmp (head[0].filetype, pgmtype)==0)
            {
                printf("\t File is PGM type image\n");
            }
            else
            {
                if(strcmp (head[0].filetype, ppmtype)==0)
                {
                    printf("\t File is PPM type image\n");
                }
            }
        }
    
    
        if ((head[0].rgb_comp_colour, RGB_COMPONENT_COLOUR)==0)
        {
            printf("\t Image is 8 bit\n");
        }
        else
        {
            if (head[0].rgb_comp_colour > RGB_COMPONENT_COLOUR)
            {
                printf("Maximum bit-depth is 8 bits\n");
            }
            else
            {
                printf("\tImage is not 8 bit\n");
            }
        }
    }
    
    
    int main(void)
    {
        
        PPMImage *img;
        int d = 0;
        char fname[100];
        printf("Enter file name: ");
        scanf("%s", fname);
        fseek(stdin,0,SEEK_END);
        fp = fopen(fname, "r");
        if (fp == NULL)
        {   
            printf("\tError while opening the file\n");
        }                        
        else    
        {
            printf("\tReading in %s\n", fname);
        }
    
    
        headercheck();
    
    
        if (strcmp (head[0].filetype, pgmtype)==0)
        {
            printf("\tReading in PGM image...\n");
            Array = malloc(head[0].width*sizeof(int*));
            for (int i=0;i<head[0].width;i++)
                Array[i] = malloc(head[0].height*sizeof(int));
            {
                if(Array = NULL)
                {
                    printf("Error allocating memory to the array");
                }
                else
                {
                    printf("Memory allocated to the PGM array sucessfully");
                }
            }
            for(int j=0;j<head[0].height;j++)
            {
                for(int i=0;i<head[0].width;i++)
                {
                    fscanf(fp, "%3d ", &Array[i][j]);
                }
            }
        }
    
    
        if (strcmp (head[0].filetype, ppmtype)==0)
        {
            RGBArray = (PPMPixel **)malloc(head[0].height*sizeof(PPMPixel*));
            for (int i=0;i<head[0].width;i++)
                RGBArray[i] = (PPMPixel *)malloc(head[0].width*sizeof(PPMPixel));
                {
                    if(RGBArray = NULL)
                    {
                        printf("Error allocating memory to the array");
                    }
                    else
                    {
                        printf("Memory allocated to the PPM array sucessfully");
                    }
                }
    
    
            PPMPixel p;
            
            //Initialising each element
            for (int j=0;j<head[0].height;j++)
            {
                for (int i=0;i<head[0].width;i++)
                {
                    fscanf(fp, "%3d %3d %3d ", &p.red, &p.green, &p.blue);
                    PPMPixel *data = &RGBArray[i][j];
                    data->red = p.red;
                    data->green = p.green;
                    data->blue = p.blue;
                }
            }
        }
    
    
        fclose(fp);
    
    
        //Save PPM Array Into New PPM File
        FILE *pf;
        int i, j;
        char fname2[100];
        printf("Enter file name: ");
        scanf("%s", fname2);
        fseek(stdin,0,SEEK_END);
        pf = fopen(fname2, "w");
        if (pf == NULL)
        {   
            printf("\tError while opening the file\n");
        }
        else    
        {
            printf("\tWriting in %s\n", fname2);
        }
    
    
        if(strcmp(head[0].filetype, pgmtype)==0)
        {
           for(j=0;j<head[0].height;j++)
            {
                fprintf(pf, "\n");
                for(i=0;i<head[0].width;i++)
                {
                    fprintf(pf, "%3d ", *(Array+j*head[0].width + i));
                }
            } 
        }
    
    
        else
        {
            for(j=0;j<head[0].height;j++)
            {
                fprintf(pf, "\n");
                for(i=0;i<head[0].width;i++)
                {
                    fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->red);
                    fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->green);
                    fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->blue);
                }
            }
        }
    
    
        printf("Yes");
        fclose(pf);
        free(Array);
        free(RGBArray);
        return 0;
    }

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    You first need to increase your warning level to the highest level in the compiler, then fix some of the errors before the ones you posted earlier:
    Code:
    arraycheck.c: In function ‘headercheck’:
    arraycheck.c:80:33: warning: left-hand operand of comma expression has no effect [-Wunused-value]
       80 |     if ((head[0].rgb_comp_colour, RGB_COMPONENT_COLOUR)==0)
          |                                 ^
    arraycheck.c: In function ‘main’:
    arraycheck.c:128:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      128 |             if(Array = NULL)
          |                ^~~~~
    arraycheck.c:150:9: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
      150 |         for (int i=0;i<head[0].width;i++)
          |         ^~~
    arraycheck.c:152:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
      152 |             {
          |             ^
    arraycheck.c:153:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      153 |                 if(RGBArray = NULL)
          |                    ^~~~~~~~
    arraycheck.c:209:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘int *’ [-Wformat=]
      209 |                 fprintf(pf, "%3d ", *(Array+j*head[0].width + i));
          |                              ~~^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                                |    |
          |                                int  int *
          |                              %3ls
    arraycheck.c:222:67: error: ‘*(RGBArray + ((sizetype)(j * head[0].width) + (sizetype)i) * 8)’ is a pointer; did you mean to use ‘->’?
      222 |                 fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->red);
          |                                                                   ^~
          |                                                                   ->
    arraycheck.c:223:67: error: ‘*(RGBArray + ((sizetype)(j * head[0].width) + (sizetype)i) * 8)’ is a pointer; did you mean to use ‘->’?
      223 |                 fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->green);
          |                                                                   ^~
          |                                                                   ->
    arraycheck.c:224:67: error: ‘*(RGBArray + ((sizetype)(j * head[0].width) + (sizetype)i) * 8)’ is a pointer; did you mean to use ‘->’?
      224 |                 fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->blue);
          |                                                                   ^~
          |                                                                   ->
    arraycheck.c:102:9: warning: unused variable ‘d’ [-Wunused-variable]
      102 |     int d = 0;
          |         ^
    arraycheck.c:101:15: warning: unused variable ‘img’ [-Wunused-variable]
      101 |     PPMImage *img;
          |               ^~~

  7. #7
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    Great. Thanks. Would you have any idea how to do that in visual studio code?

  8. #8
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by DGB_684 View Post
    Great. Thanks. Would you have any idea how to do that in visual studio code?
    I don't use any IDE, especially anything from Mickey$oft, but look at this link. If this does not work do a Google search for the version you are using, and/or any online manual for Visual Studio.

  9. #9
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    Ok. I think I managed it. But I still have the three original errors popping up despite resolving the rest.

  10. #10
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by DGB_684 View Post
    Ok. I think I managed it. But I still have the three original errors popping up despite resolving the rest.
    Now post your revised code so we can look at the remaining errors.

  11. #11
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    Cool. Thanks. Here is the updated code. But the errors were mostly minor so not much has really changed.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    #define maxheight 1080
    #define maxwidth 1920
    #define RGB_COMPONENT_COLOUR 255
    #define pgmtype "P2"
    #define ppmtype "P3"
    
    
    typedef struct
    {
        int red, green, blue;
    } PPMPixel;
    
    
    typedef struct
    {
        int x, y;
        PPMPixel *data;
    } PPMImage;
    
    
    typedef struct 
    {
        int rgb_comp_colour;
        char buff[16];
        char filetype[2];
        int height;
        int width;
    } PPMHead;
    PPMHead head[3];
    
    
    int **Array;
    PPMPixel **RGBArray;
    FILE *fp;
    
    
    void headercheck ()
    {
        fscanf(fp, "%s %d %d %d", head[0].filetype, &head[0].width, &head[0].height, &head[0].rgb_comp_colour);
        printf("%s %d %d %d", head[0].filetype, head[0].width, head[0].height, head[0].rgb_comp_colour);
    
    
        if (head[0].width > maxwidth || head[0].height > maxheight)
        {
            printf("\tInvalid image size. The maximum value of image is 1920x1080.\n");
            printf("\tImage size is %d x %d\n", head[0].width, head[0].height);
        }
        else
        {
            printf("\tImage size is valid\n");
            printf("\tImage size is %d x %d\n", head[0].width, head[0].height);
        }
    
    
        if ((strcmp (head[0].filetype, pgmtype)!=0) && (strcmp (head[0].filetype, ppmtype)!=0))
        {
            printf("\tInvalid filetype\n");
        }
        else
        {
            if(strcmp (head[0].filetype, pgmtype)==0)
            {
                printf("\t File is PGM type image\n");
            }
            else
            {
                if(strcmp (head[0].filetype, ppmtype)==0)
                {
                    printf("\t File is PPM type image\n");
                }
            }
        }
    
    
        if ((head[0].rgb_comp_colour == RGB_COMPONENT_COLOUR))
        {
            printf("\t Image is 8 bit\n");
        }
        else
        {
            if (head[0].rgb_comp_colour > RGB_COMPONENT_COLOUR)
            {
                printf("Maximum bit-depth is 8 bits\n");
            }
            else
            {
                printf("\tImage is not 8 bit\n");
            }
        }
    }
    
    
    int main(void)
    {
        char fname[100];
        printf("Enter file name: ");
        scanf("%s", fname);
        fseek(stdin,0,SEEK_END);
        fp = fopen(fname, "r");
        if (fp == NULL)
        {   
            printf("\tError while opening the file\n");
        }                        
        else    
        {
            printf("\tReading in %s\n", fname);
        }
    
    
        headercheck();
    
    
        if (strcmp (head[0].filetype, pgmtype)==0)
        {
            printf("\tReading in PGM image...\n");
            Array = malloc(head[0].width*sizeof(int*));
            for (int i=0;i<head[0].width;i++)
                Array[i] = malloc(head[0].height*sizeof(int));
            {
                if((Array = NULL))
                {
                    printf("Error allocating memory to the array");
                }
                else
                {
                    printf("Memory allocated to the PGM array sucessfully");
                }
            }
            for(int j=0;j<head[0].height;j++)
            {
                for(int i=0;i<head[0].width;i++)
                {
                    fscanf(fp, "%3d ", &Array[i][j]);
                }
            }
        }
    
    
        if (strcmp (head[0].filetype, ppmtype)==0)
        {
            printf("Error 1");
            RGBArray = (PPMPixel **)malloc(head[0].height*sizeof(PPMPixel*));
            for (int i=0;i<head[0].width;i++)
            {
                RGBArray[i] = (PPMPixel *)malloc(head[0].width*sizeof(PPMPixel));
            }
                {
                    if((RGBArray = NULL))
                    {
                        printf("Error allocating memory to the array");
                    }
                    else
                    {
                        printf("Memory allocated to the PPM array sucessfully");
                    }
                }
    
    
            PPMPixel p;
            
            printf("Error 2");
            //Initialising each element
            for (int j=0;j<head[0].height;j++)
            {
                for (int i=0;i<head[0].width;i++)
                {
                    fscanf(fp, "%3d %3d %3d ", &p.red, &p.green, &p.blue);
                    PPMPixel *data = &RGBArray[i][j];
                    data->red = p.red;
                    data->green = p.green;
                    data->blue = p.blue;
                }
                printf("Erroe");
            }
        }
    
    
        printf("Error 3");
        fclose(fp);
    
    
        printf("Error 4");
    
    
        //Save PPM Array Into New PPM File
        FILE *pf;
        int i, j;
        char fname2[100];
        printf("Enter file name: ");
        scanf("%s", fname2);
        fseek(stdin,0,SEEK_END);
        pf = fopen(fname2, "w");
        if (pf == NULL)
        {   
            printf("\tError while opening the file\n");
        }
        else    
        {
            printf("\tWriting in %s\n", fname2);
        }
    
    
        if(strcmp(head[0].filetype, pgmtype)==0)
        {
           for(j=0;j<head[0].height;j++)
            {
                fprintf(pf, "\n");
                for(i=0;i<head[0].width;i++)
                {
                    fprintf(pf, "%3d ", **(Array+j*head[0].width + i));
                }
            } 
        }
    
    
        else
        {
            for(j=0;j<head[0].height;j++)
            {
                fprintf(pf, "\n");
                for(i=0;i<head[0].width;i++)
                {
                    fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->red);
                    fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->green);
                    fprintf(pf, "%3d ", (RGBArray+j*head[0].width + i)->blue);
                }
            }
        }
    
    
        printf("Yes");
        fclose(pf);
        free(Array);
        free(RGBArray);
        return 0;
    }

  12. #12
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    First of all, please look at lines 122 & 123, followed by a block. Is this correct?
    Second, I am not that familiar with image processing so I might yield to someone that is more familiar with the code.

  13. #13
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    I think that is an accident. The malloc should be in the for loop. Yes I guess image processing not everyone is familiar with which is why I've found it so hard to get help on this. Its more to do with dynamically allocating arrays and pointers tbh. But thanks for the help so far.

  14. #14
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    Still warnings and errors left. VS 2019 with C17 standard and /W4

    Error E0132 expression must have pointer-to-struct-or-union type but it has type "PPMPixel **" C_CONSOLE.c 232
    Error E0132 expression must have pointer-to-struct-or-union type but it has type "PPMPixel **" C_CONSOLE.c 233
    Error E0132 expression must have pointer-to-struct-or-union type but it has type "PPMPixel **" C_CONSOLE.c 234
    Warning C6031 Return value ignored: 'fscanf'. C_CONSOLE.c 48
    Warning C6031 Return value ignored: 'fscanf'. C_CONSOLE.c 142
    Warning C6031 Return value ignored: 'fscanf'. C_CONSOLE.c 176
    Warning C6031 Return value ignored: 'scanf'. C_CONSOLE.c 199
    Warning C6054 String 'fname2' might not be zero-terminated. C_CONSOLE.c 201
    Warning C6387 'pf' could be '0': this does not adhere to the specification for the function 'fprintf'. C_CONSOLE.c 229
    Warning C6387 'pf' could be '0': this does not adhere to the specification for the function 'fclose'. C_CONSOLE.c 241
    Error C2223 left of '->red' must point to struct/union C_CONSOLE.c 232
    Warning C4473 'fprintf' : not enough arguments passed for format string C_CONSOLE.c 232
    Error C2223 left of '->green' must point to struct/union C_CONSOLE C_CONSOLE.c 233
    Warning C4473 'fprintf' : not enough arguments passed for format string C_CONSOLE.c 233
    Error C2223 left of '->blue' must point to struct/union C_CONSOLE.c 234
    Warning C4473 'fprintf' : not enough arguments passed for format string C_CONSOLE.c 234


  15. #15
    Registered User
    Join Date
    Dec 2021
    Posts
    34
    Quote Originally Posted by thmm View Post
    Still warnings and errors left. VS 2019 with C17 standard and /W4
    What is happening there? I never got any of those?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 10-08-2010, 05:35 PM
  2. error message
    By ke121885 in forum C Programming
    Replies: 7
    Last Post: 10-19-2009, 01:31 PM
  3. Error message
    By lionking30685 in forum C Programming
    Replies: 2
    Last Post: 11-15-2007, 02:00 AM
  4. Error message...
    By Meganan in forum C++ Programming
    Replies: 6
    Last Post: 10-08-2005, 12:44 AM
  5. error message
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2002, 07:14 PM

Tags for this Thread