Suppose I have a function like that

char OnRelease() 
{ 
   int i,j,k; 
   int row[4]={PIN_A0,PIN_A1,PIN_A2,PIN_A3}; 
   int col[4]={PIN_D3,PIN_D2,PIN_D1,PIN_D0}; 
   char array[16]={'1','4','7','<','2','5','8','0','3','6','9','>','C','&','E','M'}; 
   set_tris_a(0xff); 
   set_tris_d(0x00); 
   k=0; 
   for(i=0;i<4;i++) 
   { 
   output_d(0xff); 
   output_low(col[i]); 
   for(j=0;j<4;j++) 
   { 
      if(input(row[j])==0) 
      { 
         do 
         { 
         } 
         while(input(row[j])==0); 
         return array[k]; [B]//// will jump out of this function with the value I got ??? [/B]
      } 
   k++; 
   } 
   } 
   return null; [B]//????? [/B]
}

is "return array[k];" will exit the loop and also end the function ?
is "return null;" exist and I can use this "if (something != null)"
Thanks so much !!!

yes any kind of return statement will end the function.

I can use this "if (something != null)"

You could, because NULL (all caps) is defined (on all systems I've ever worked on) as 0 which is an int. (#define NULL 0)

char OnRelease()
{
...
...
return null; //return a char value, but null is int one ???
}
then my code is wrong ? ...

You should return NULL (in CAPITALS), then it should return 0;

>You should return NULL (in CAPITALS), then it should return 0
No, you shouldn't use NULL except in a pointer context because it's allowed to be (and often) defined thusly:

#define NULL ( (void*)0 )

If you want to return a null character, return '\0'.

nm

nm

What about New Mexico?

Uhm ... thanks all, now if I attempt to use pointer, what is the best of coding ?
is below code all right ?

int *keyPressed;  //change here ...
 play:
   keyPressed=OnRelease();
   if(keyPressed != NULL)
   {
       WrDat2Lcd(*keyPressed); //..and here ???
   }
   goto play;
int OnRelease()
{
   int i,j,k;
   int value[4]={0x07,0x0B,0x0D,0x0E};
   int array[16]={0x31,0x34,0x37,0x3C,0x32,0x35,0x38,0x30,0x33,0x36,0x39,0x3E,0x43,0x26,0x45,0x4D};
   set_tris_a(0x0f);
   set_tris_d(0xf0);
   k=0;
   for(i=0;i<4;i++)
   {
      output_d(value[i]);
      delay_us(100);
      for(j=0;j<4;j++)
      {
         if(!input(40+j))
         {
            do
            {
            }
            while(!input(40+j));
            return array[k];
         }
         else
            k++;
      }
   }
   return NULL;
}
int *keyPressed;  //change here ...
 play:
   keyPressed=OnRelease();
   if(keyPressed != NULL)
   {
       WrDat2Lcd(*keyPressed); //..and here ???
   }
   goto play;
int OnRelease()    // returns an integer, not an int*

Function OnRelease returns an integer. keyPressed is type int*. You are assigning an integer value to an int* variable in line 3 above. You don't want to do that. Also, later in function OnRelease, you are returning NULL:

return NULL;

NULL is not an integer, so you don't want to do that. As far as this line,

WrDat2Lcd(*keyPressed); //..and here ???

I don't know what type of parameter WrDat2Lcd is supposed to take so I don't know if it's an error or not. Is that a function you wrote?


P.S. Possibly off topic but does this code need to be part of some function? It kind of looks like it's floating around without belonging to any function. Can you do that in C?

int *keyPressed;  //change here ...
 play:
   keyPressed=OnRelease();
   if(keyPressed != NULL)
   {
       WrDat2Lcd(*keyPressed); //..and here ???
   }
   goto play;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.