Thread: warning: passing argument makes pointer from integer without a cast

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    4

    warning: passing argument makes pointer from integer without a cast

    Hello there

    I am having a problem with trying to draw a curve through the data points on my graph.

    I can do it with cpgdraw fine, since it runs within the while loop. However, attempting to use cpgdraw with multiple data sets results in the code drawing lines between them, which obviously leads to a very messy and nonsensical graph.

    When trying with cpgline though i get these errors:

    electro.c:43: warning: passing argument 2 of `cpgline` makes pointer from integer without a cast
    electro.c:43: error: incompatible type for argument 3 of `cpgline`

    Unfortunately, my university was not very good at teaching us c properly and so me (and the other students) are learning on the fly which as you can imagine leads to issues like these which are probably simple but just escape me.

    Code:
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <cpgplot.h>
    
    #define MAX 50
    #define FILENAMELENMAX 100
    
    struct EMinfo {
      int position, angle1, angle2, angle3, angle4, angle5, angle6;
      float voltage1, voltage2, voltage3, volatge4, voltage5, voltage6; };
    
    int main()
    {
      struct EMinfo data[MAX]; 
      int cnt;
      char datafile [FILENAMELENMAX];
      FILE *f;
      
      int xmin, xmax;
      float ymin, ymax;
    
      printf("Please input data file location\n");
      scanf("%s", datafile );
      
      f = fopen(datafile,"r");
    
      cnt = 0;
      xmax = 90;
      xmin = 20;
      ymax = 2;
      ymin = 0; 
      
      cpgbeg(0, "?", 1, 1);
      cpgenv(xmin, xmax, ymin, ymax, 0, 1);
      cpglab("Angle /o", "Voltage /mV", "Transmitted intensity as a function of angle for Sand");
    
        while(!feof(f) && cnt < MAX){
          fscanf(f, "%d %g %d %g\n", &data[cnt].angle1, &data[cnt].voltage1, &data[cnt].angle2, &data[cnt].voltage2);
    
          printf("anglewIR = %d, voltagewIR = %g, angledIR = %d, voltagedIR = %g\n", data[cnt].angle1, data[cnt].voltage1, data[cnt].angle2, data[cnt].voltage2); 
             
                 cpgline(50, data[cnt].angle1, data[cnt].voltage1);
    
          data[cnt].position = cnt;
          cnt++;
        }
       
       cpgend();
     
      fclose(f);
    
      printf("Read %d records from the data file\n", cnt);
    }
    Any help is greatly appreciated, you might have to treat me like a complete idiot with c though

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Code:
    void cpgline(int n, const float *xpts, const float *ypts);
    This is what I found for the prototype of that function. You are passing int in your second argument.
    Last edited by camel-man; 03-07-2012 at 05:04 PM.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    thank you

    hmm i changed angle to a float and the pointer error was solved

    however i still get incompatible type for both of them, so essentially cpgline does not like arrays..... how the hell am i supposed to plot the graph now...

  4. #4
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You need to pass a pointer to a float, right now you are passing single floats in your arguments.

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    right, thank you

    ill probably be a while as i have to look up how to do what you say

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    on a slightly unrelated note, is it possible to have 2 arrays together?

    i mean for example the program reads data values from a .txt file using a struct: data[cnt].angle1, is there a way to make the struct parameter an array as well? so data[cnt].angle[i].

    i prefer streamlining my code as much as possible but when i tried this it did not work, but my knowledge of c is so limited i wouldn't know if its even possible.

    thank you

  7. #7
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Yes in C anything is possible ! If i am understanding your question, you want an array in your struct?

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I don't know exactly what you mean by "streamlining your code" in this case. There's no point in being efficient if you can't actually solve the problem at hand. Don't worry taking up space or processing time using arrays inside your structs, if that's what needs to be done to solve the problem. Also, don't worry about having to type a few extra characters, if that's what's needed. Rule of thumb: write your code in the clearest, simplest and easiest to maintain manner possible. Only when it's proven that it is too slow or bloated by a lot, do you bother optimizing.

    Yes, it's possible to have an array in your struct, and an array seems to be a likely choice for what the function wants. But a quick search didn't come up with any good documentation on this library you're using, so double check whatever documentation you have. You would need to declare the struct so that angle1 is an array of floats:
    Code:
    #define NUM_ANGLES   42    // or whatever the correct number is
    struct EMinfo {
        ...
        float angle1[NUM_ANGLES];
        ...
    };
    Then, when you pass it into the function, you just pass in the name of the array, i.e. drop the last set of brackets:
    Code:
    cpgline(50, data[cnt].angle, ...);
    That passes the whole array (which a function sees as a pointer to the type of thing in the array) to the function. data[cnt].angle[i] would be just one element of the array, and would be a plain float, similar to the (incorrect) way you're using it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2011, 11:36 AM
  2. Replies: 2
    Last Post: 04-20-2011, 12:24 PM
  3. Replies: 8
    Last Post: 08-28-2009, 07:49 AM
  4. Replies: 4
    Last Post: 01-27-2009, 02:33 PM
  5. Replies: 2
    Last Post: 05-21-2008, 02:52 PM