Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

functions and pointers

Status
Not open for further replies.

SlykFX

Programmer
Oct 12, 2002
76
GB
Apologises if this is covered somewhere else but i did a search and couldnt find what i need

im trying to pass an int pointer from one function to another and cos i dont understand the question, the ode below explains a little better

Code:
int main(void)
{
  int location[maxNum];
  getValues(location);
}
void getValues(int *l)
{
  *l = getInput(???); // what is it i need to pass here?
}
void getInput(int *p)
{
}

im either more tired than i feel or its a little more difficult than this

thanks for any help

I can't be bothered to have a sig!
 
This depends on what is going to happen in getInput(), but here's my best guess.

Code:
int main(void)
{
  int location[maxNum];
  getValues(location);
}
void getValues(int *l)
{
  getInput(l);  // like this 
  // *l = getInput(???); // can't assign a value from a void function.
}
void getInput(int *p)
{
  // assumes you're going to get input for individual array elements
  int i;

  for (i = 0; i < maxNum; i++)
    p[i] = someValue; // assign a value however you want.
}
 
the "*l = getInput(???);" line in my first post was a typo - mixed to functions together
when copying it to here - sorry for the confusion


ive just changed my code to match

Code:
int main(void)
{
  int location[maxNum];
  getValues(location);
}
void getValues(int *l)
{
  getInput(l);
  // has error checking and other function calls in this here
}
void getInput(int *p)
{
  // gets values to populate the array
}

however im still receiving the same error

cc: Warning: part2.c, line 309: In this declaration, the type of the
function "getInput" is not compatible with the earlier implicit declar
ation of "getInput" at line number 223 in file part2.c. (no
tcompatimp)
void getInput(int *l)
-----^

ive checked everything i can think of concerning the function and its call but cant see anything wrong with it
and yes the prototype is good

I can't be bothered to have a sig!
 
An implicit declaration results when you use a function before it's declaration. You need to either declare the function before it's use, or even better, prototype your functions, either in a header file that you then include, or at the beginning of your code, right after any includes.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <whateverElse.h>

void getInput(int *p); // these are the function prototypes
void getValues(int *l);

int main(void)
{
  int location[maxNum];
  getValues(location);
}
void getValues(int *l)
{
  getInput(l);
  // has error checking and other function calls in this here
}
void getInput(int *p)
{
  // gets values to populate the array
}
 
the prototype is fine

however ive just noticed the problem anyway
i had used an upper case i not an l in my spelling of the function
the difference between I and l (uppercase i and lowercase L) is only minor at the best of times

sorry about this guys, i guess i am alot tireder than i thought

but thanks anyway as it did confirm what i needed to check :)

I can't be bothered to have a sig!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top