I am using an 2d array to search for the key 32 using pointers.. Now whenever i try to compile i get an linker error saying undefined symbol find_key(int *far,int,int)..
I know the error is with the use of pointers and the way i am passing them... Can anyone help me out -
#include<stdio.h>
-
#include<conio.h>
-
#include<stdlib.h>
-
#define N 4
-
void find_key(int *,int,int);
-
-
void main(){
-
clrscr();
-
srand((unsigned)time(NULL));
-
-
int arr[N][N];
-
int *p;
-
int key=32;
-
int len=16;
-
int count=0;
-
for(p=&arr[0][0];p<=&arr[N-1][N-1];p++){
-
if(count==4){
-
*p=32;
-
}
-
else{
-
*p=rand()%10+1;
-
}
-
count++;
-
}
-
for(p=&arr[0][0];p<=&arr[N-1][N-1];p++)
-
printf("\n%d",*p);
-
-
find_key(&arr[0][0],len,key);
-
getch();
-
}
-
void find_temp(int *a,int n,int k){
-
int *p;
-
for(p=a;p<a+n;p++){
-
if(*p==k)
-
printf("\nfound key at %d",p);
-
else
-
printf("\nnot foumd");
-
}
-
}
4 2324
Look at your line 31 - void find_temp(int *a,int n,int k){
Change the function name to 'find_key', cause that's what you declared above 'main'. - void find_key(int *a,int n,int k){
See if that works...
@ashitpro
Oh yeah it works sorry silly me... i didnt check with the function names..
anyways i'll experiment with different pointer notations of passing an argument.. and if i'm stuck i'll post it here
anyways thanks a lot
Now in the above code if i want to process only the rows.. this code works fine.. if i want to send each row one by one to the function to find the key can i pass the first array element arr[0] like find_key(arr[i],len,key) in the function call?? how would i write a function prototype for that?? I want to send each row of the 2d array one by one to the function to find the key
I am really stuck as i could not understand parameter passing of pointers in 2d arrays to functions?? Can anyone explain that concept please?? - for(p=arr[i];p<=arr[i]+N;p++){
-
printf("\n%d",*p);
Banfa 9,065
Expert Mod 8TB
The way you are current declaring and calling find_key is not, in my opinion, a good design.
You might want to start by reading our arrays revealed tutorial.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Noah Spitzer-Williams |
last post by:
Hello guys,
I'm itinerating through my array using pointers in this fashion:
image is unsigned char image
do {
cout << "image byte is: " << *image << endl;
|
by: arun |
last post by:
suppose i have a pointer to an array of integers.can i initialize each
member of the array using pointers?plz explain
|
by: mVosa |
last post by:
I have this piece of code in a funtion which is trying to retrieve the memory address of values that are stored in a 2D array, using pointers...Could I get help or tips on how to do this please...
|
by: Bond |
last post by:
i have written this program of entering 2-d array through
pointers.this shows number of errors.please help me out.
#include<stdio.h>
#include<alloc.h>
void aread(int*,int*,int*);
void...
|
by: EJSpin |
last post by:
Hey guys, I have put together a class called Mu
class Mu
{
private:
double **s;
int velocity,numbers;
double sPeak,muPeak,mu1;
...
|
by: niteshpanchal |
last post by:
Hi,
I want to assign array of 5 using pointer.
How can i ?
|
by: niteshpanchal |
last post by:
Hi,
How to assign dynamic array using pointers for string.
|
by: StevenChiasson |
last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller.
This is more or less, your...
|
by: hanaa |
last post by:
Hello
I need to call a function that returns a 2D array. I need to dynamically allocate memory for the array in the callee. Now, I return using a pointer to a pointer.
In the callee, I...
|
by: AnagJohari |
last post by:
main( )
{
int a = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf("%u %u %u %d \n",a,*a,**a,***a);
printf("%u %u %u %d \n",a+1,*a+1,**a+1,***a+1);
}
If the location of an array start...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |