7 Replies - 1147 Views - Last Post: 14 October 2012 - 12:14 PM Rate Topic: -----

#1 miked89  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Makes pointer from integer without a cast Warning

Posted 12 October 2012 - 09:53 PM

Hello Friends!

I am getting three warnings when i compile. My first question is will this cause an error in the execution? and second if so how can i fix it?
I am new to C so it might be a quick fix i just don't know what to do. Any help here would be greatly appreciated.



Here are the warnings im getting, regarding these lines of code respectively

p2.c:95: warning: initialization makes pointer from integer without a cast
p2.c:128: warning: passing arg 1 of `open' makes pointer from integer without a cast
p2.c:137: warning: passing arg 1 of `open' makes pointer from integer without a cast



  if(newargv[1] == NULL)
                                        {
                                        char *goHome = getenv("HOME");




  if (leftFlag == 1)
                        {
                        input_fd = open(ioArray[0], O_RDONLY);  //here

                        dup2(input_fd, STDIN_FILENO);
                        leftFlag = 0;
                        close(input_fd);
                        }

                if(rightFlag == 1)
                        {
                        output_fd = open(outArray[0], O_WRONLY, 0400 | 0200);  //and here
                        dup2(output_fd, STDOUT_FILENO);
                        rightFlag = 0;
                        close(output_fd);








Thanks for the help!
Michael

Is This A Good Question/Topic? 1
  • +

Replies To: Makes pointer from integer without a cast Warning

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Makes pointer from integer without a cast Warning

Posted 12 October 2012 - 10:10 PM

Can you post the declaration of outArray and ioArray
Was This Post Helpful? 1
  • +
  • -

#3 miked89  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: Makes pointer from integer without a cast Warning

Posted 13 October 2012 - 04:59 PM

Sure, here is the declaration:


char ioArray[STORAGE];
char outArray[STORAGE];



Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Makes pointer from integer without a cast Warning

Posted 13 October 2012 - 05:32 PM

Quote

input_fd = open(ioArray[0], O_RDONLY);


open takes a character "pointer" as it's first argument.

Can you tell me the type of ioArray[0]. Answering that question will lead to the solution to your problem
Was This Post Helpful? 0
  • +
  • -

#5 miked89  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: Makes pointer from integer without a cast Warning

Posted 13 October 2012 - 05:41 PM

Sure thing.
void parse(char *t, char **ptrArray,char *ioArray, char *outArray);



parse(s, newargv, ioArray, outArray);






void parse(char *t,char **ptrArray, char *io, char *out)
{

int j=0;
int i, ch;
ptrArray[0] = t ;
int c;
int x;

/***********************Begin Parsing ********************/



for(;;)/>{


c = getword(t);



        if(c ==-1)
                {
                printf("p2 has terminated./n");
                exit(0);
                }

        if(c ==0)
                {
                ptrArray[j]= NULL;
                return;
                }

        if(c ==1){
                if(*t =='&')
                        {
                        ptrArray[j]=NULL;
                        isBackground = 1;
                        return;
                        }
                if(*t == '<')
                        {
                        leftFlag = 1;
                        x = getword(io);
                        io = io + x +1;
                        continue;
                        }
                if(*t == '>')
                        {
                        rightFlag = 1;
                        x = getword(out);
                        io = io + x + 1;
                        continue;
                        }
                }








When the function getword is called it returns the integer length of the word and places the characters in a char array
at io.
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Makes pointer from integer without a cast Warning

Posted 14 October 2012 - 04:49 AM

You didn't answer jjl's question. Here's the question again:

Quote

Can you tell me the type of ioArray[0]


Answer that question.
Was This Post Helpful? 0
  • +
  • -

#7 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1629
  • View blog
  • Posts: 3,092
  • Joined: 30-May 10

Re: Makes pointer from integer without a cast Warning

Posted 14 October 2012 - 10:29 AM

Unless I'm missing something, post #3 tells you all you need to know, and that perhaps it should be
input_fd = open(ioArray, O_RDONLY);
Was This Post Helpful? 0
  • +
  • -

#8 miked89  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: Makes pointer from integer without a cast Warning

Posted 14 October 2012 - 12:14 PM

Yes that fixed the problem thank you very much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1