Thread: issues with program need help

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    33

    issues with program need help

    i keep getting warnings about the functions making pointer from integer without a cast can anyone help me.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    
    #define  BUFFER_SIZE  70
    #define  TRUE          1
    #define  FALSE         0
    int value;
    int menu_number=0;
    int**  img;
    int** temppicx, temppicy;
    int**  img,sobelout;
    int    numRows;
    int    numCols;
    int    maxVal;
    FILE*  fo1;
    
    void addtopixels(int** imgtemp, int value);
    void  writeoutpic(char* fileName, int** imgtemp);
    int** readpic(char* fileName);
    void  readHeader(FILE* imgFin);
    int   isComment(char* line);
    void  readImgID(char* line);
    void  readImgSize(char* line);
    void  readMaxVal(char* line);
    int** setImage();
    void  readBinaryData(FILE* imgFin, int** imgtemp);
    void sobelfunc(int** pic, int** edges, int** tempx, int** tempy);
    int main()
    {
       while(menu_number != 4){
    
           printf("please choose an option\n");
           printf("1) Add Brightness)\n");
           printf("2) Subtract Pictures 2\n");
           printf("3) Edge Highlighter\n");
           printf("4) Quit\n");
           scanf("%d", &menu_number);
    
    if( menu_number==1)
      {
      char fileName[BUFFER_SIZE];
            int i,j,rows,cols;
            char ci;
    
    
            printf("Enter image filename: ");
            scanf("%s", fileName);
    
            img = readpic(fileName);
    
            printf("Successfully read image file '%s'\n", fileName);
    
    	printf("Please enter in brightness change\n");
    		scanf("%d", &value);
    
    	addtopixels(img,value);
    
    printf("Enter image filename for output: ");
            scanf("%s", fileName);
    
            writeoutpic(fileName,img);
    
            free(img);
            img = NULL;
    
            return(EXIT_SUCCESS);
    
    
    
    
    if( menu_number==2)
    {
    
    
    
    
    
    
    
    
    if( menu_number==3)
    {
    char fileName[BUFFER_SIZE];
            int i,j,rows,cols;
            char ci;
    
    
            printf("Enter image filename: ");
            scanf("%s", fileName);
    
            img = readpic(fileName);
    
            printf("Successfully read image file '%s'\n", fileName);
    
    	sobelout= setImage();
    
            temppicx= setImage();
            temppicy= setImage();
    
            sobelfunc(img,sobelout,temppicx,temppicy); 
    
    
            printf("Enter image filename for output: ");
            scanf("%s", fileName);
    
            writeoutpic(fileName,sobelout);
    
    	
    
    
    }
    
    void addtopixels(int** imgtemp, int value)
    {  
            int i,j;
            
            for (i=0;i<numRows;i++)
            { for (j=0;j<numCols;j++)
                    {
                      imgtemp[i][j] += value;
                    }
            }
    }
    
    void writeoutpic(char* fileName, int** imgtemp)
    {
            int i,j;
            char ci;
            FILE* fo1;
            
            if((fo1 = fopen(fileName, "wb")) == NULL)
            {
                    printf("Unable to open out image file '%s'\n", fileName);
                    exit(EXIT_FAILURE);
            }
    
            fprintf(fo1,"P5\n");
            fprintf(fo1,"%d %d\n", numRows, numCols);
            fprintf(fo1,"255\n");
    
            for (i=0;i<numRows;i++)
            { for (j=0;j<numCols;j++)
                    {
                      ci   =  (char) (imgtemp[i][j]);
                      fprintf(fo1,"%c", ci);
                    }
            }
    }
    
    
    
    
    int** readpic(char* fileName)
    {
            FILE* imgFin;
            int** imgtemp;
    
            if((imgFin = fopen(fileName, "rb")) == NULL)
            {
                    printf("Unable to open image file '%s'\n", fileName);
                    exit(EXIT_FAILURE);
            }
    
            readHeader(imgFin);
    
    
            imgtemp  = setImage();
    
            readBinaryData(imgFin, imgtemp);
    
            fclose(imgFin);
            
            return  imgtemp;
    
    }
    
    void readHeader(FILE* imgFin)
    {
            int  haveReadImgID   = FALSE;
            int  haveReadImgSize = FALSE;
            int  haveReadMaxVal  = FALSE;
            char line[BUFFER_SIZE];
    
            while(!(haveReadImgID && haveReadImgSize && haveReadMaxVal))
            {
                    fgets(line, BUFFER_SIZE, imgFin);
    
                    if((strlen(line) == 0) || (strlen(line) == 1))
                            continue;
    
                    if(isComment(line))
                            continue;
    
                    if(!(haveReadImgID))
                    {
                            readImgID(line);
                            haveReadImgID = TRUE;
                    }
                    else if(!(haveReadImgSize))
                    {
                            readImgSize(line);
                            haveReadImgSize = TRUE;
                    }
                    else if(!(haveReadMaxVal))
                    {
                            readMaxVal(line);
                            haveReadMaxVal = TRUE;
                    }
            }
    
    }
    
    int isComment(char *line)
    {
            if(line[0] == '#')
                    return(TRUE);
    
            return(FALSE);
    }
    
    void readImgID(char* line)
    {
            if(strcmp(line, "P5\n") != 0)
            {
                    printf("Invalid image ID\n");
                    exit(EXIT_FAILURE);
            }
    }
    
    void readImgSize(char* line)
    {
            unsigned i;
    
            for(i = 0; i < strlen(line); ++i)
            {
                    if(!((isdigit((int) line[i])) || (isspace((int) line[i]))))
                    {
                            printf("Invalid image size\n");
                            exit(EXIT_FAILURE);
                    }
            }
    
            sscanf(line, "%d %d", &numRows, &numCols);
    }
    
    void readMaxVal(char* line)
    {
            unsigned i;
    
            for(i = 0; i < strlen(line); ++i)
            {
                    if(!((isdigit((int) line[i])) || (isspace((int) line[i]))))
                    {
                            printf("Invalid image max value\n");
                            exit(EXIT_FAILURE);
                    }
            }
    
            maxVal = atoi(line);
    }
    
    int** setImage()
    {
            int** imgtemp;
            unsigned i;
    
            imgtemp = (int**) calloc(numRows, sizeof(int*));
    
            for(i = 0; i < numRows; ++i)
            {
                    imgtemp[i] = (int*) calloc(numCols, sizeof(int));
            }
            return imgtemp;
    }
    
    void readBinaryData(FILE* imgFin, int** imgtemp)
    {
            unsigned  i;
            unsigned  j;
            for(i = 0; i < numRows; ++i)
            {
                    for(j = 0; j < numCols; ++j)
                    {
                                imgtemp[i][j] = 
                                fgetc(imgFin);
                    }
            }
    }
    
    void sobelfunc(int** pic, int** edges, int** tempx, int** tempy){
    
            int maskx[3][3] = {{-1,0,1},{-2,0,2},{-1,0,1}};
            int masky[3][3] = {{1,2,1},{0,0,0},{-1,-2,-1}};
            int maxival;
    
    
            
     
            int i,j,p,q,mr,sum1,sum2;
            double threshold;
             
    
            mr = 1;
    
    
            for (i=mr;i<numRows-mr;i++)
            { for (j=mr;j<numCols-mr;j++)
              {
                 sum1 = 0;
                 sum2 = 0;
                 for (p=-mr;p<=mr;p++)
                 {
                    for (q=-mr;q<=mr;q++)
                    {
                       sum1 += pic[i+p][j+q] * maskx[p+mr][q+mr];
                       sum2 += pic[i+p][j+q] * masky[p+mr][q+mr];
                    }
                 }
                 tempx[i][j] = sum1;
                 tempy[i][j] = sum2;
              }
            }
    
            maxival = 0;
            for (i=mr;i<numRows-mr;i++)
            { for (j=mr;j<numCols-mr;j++)
              {
                 edges[i][j]=(int) (sqrt((double)((tempx[i][j]*tempx[i][j]) +
                                          (tempy[i][j]*tempy[i][j]))));
                 if (edges[i][j] > maxival)
                    maxival = edges[i][j];
    
               }
            }
    
    
    
            for (i=0;i<numRows;i++)
              { for (j=0;j<numCols;j++)
                {
                 edges[i][j] = ((edges[i][j]*1.0) / maxival) * 255;            
                 
                }
              }
    }

  2. #2
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I might help if you gave the precise error message(s) - my mind-reading skills are probably not
    as good as yours!!

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    33
    passing arg 2 of sobelfunc makes pointer from integer without a cast
    passing arg 4 of sobelfunc makes pointer from integer without a cast
    passing arg 2 of writeoutpic makes pointer from integer without a cast

    sorry

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    33
    anyone ??

  5. #5
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    OK in setImage you allocate an arrays of pointer to integers.
    It looks lilke in sobel func that you try and put an integer into this array.
    Or something along those lines.

    I think you should have declared some integers somewhere but I think you have declared an
    array of pointers to integers (in calloc) and then tried to put integers into them.
    If I have read it correctly.
    Probably something along those lines anyway.
    Looks pretty complicated, whatever you are trying to do, but you are definately putting an integer somewhere
    and it seem that is where the compiler thinks a pointer should be.
    Maybe the error message should say, - warning you are trying to put an integer where a pointer (to an int) should be?
    Try making the cast a pointer at an int rather than in int where you set 'edges', that might compile (but not work!!).
    Code:
    edges[i][j]=(int) (sqrt((double)((tempx[i][j]*tempx[i][j]) +
                                          (tempy[i][j]*tempy[i][j]))));
    eg
    Code:
    edges[i][j]=(int *) (sqrt((double)((tempx[i][j]*tempx[i][j]) +
                                          (tempy[i][j]*tempy[i][j]))));
    Last edited by esbo; 04-02-2008 at 10:20 PM.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > int** img,sobelout;
    Despite your attempted 'association' of the pointers with the int, it is only img which is an int** variable, sobelout remains just an int.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Continued issues with Winows Errors when running program
    By hpteenagewizkid in forum C Programming
    Replies: 6
    Last Post: 11-14-2006, 03:51 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  5. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM