473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Searching an 2d array using pointers

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
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #define N 4
  5. void find_key(int *,int,int);
  6.  
  7. void main(){
  8.     clrscr();
  9.     srand((unsigned)time(NULL));
  10.  
  11.     int arr[N][N];
  12.     int *p;
  13.         int key=32;
  14.         int len=16;
  15.     int count=0;
  16.     for(p=&arr[0][0];p<=&arr[N-1][N-1];p++){
  17.         if(count==4){
  18.             *p=32;
  19.         }
  20.         else{
  21.         *p=rand()%10+1;
  22.     }
  23.         count++;
  24.     }
  25.     for(p=&arr[0][0];p<=&arr[N-1][N-1];p++)
  26.         printf("\n%d",*p);
  27.  
  28.     find_key(&arr[0][0],len,key);
  29.     getch();
  30. }
  31. void find_temp(int *a,int n,int k){
  32.     int *p;
  33.     for(p=a;p<a+n;p++){
  34.         if(*p==k)
  35.             printf("\nfound key at %d",p);
  36.         else
  37.             printf("\nnot foumd");
  38.     }
  39. }
Sep 27 '10 #1
4 2324
ashitpro
542 Expert 512MB
Look at your line 31

Expand|Select|Wrap|Line Numbers
  1. void find_temp(int *a,int n,int k){
Change the function name to 'find_key', cause that's what you declared above 'main'.

Expand|Select|Wrap|Line Numbers
  1. void find_key(int *a,int n,int k){
See if that works...
Sep 27 '10 #2
@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
Sep 27 '10 #3
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??

Expand|Select|Wrap|Line Numbers
  1. for(p=arr[i];p<=arr[i]+N;p++){
  2.         printf("\n%d",*p);
Sep 27 '10 #4
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.
Sep 27 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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;
31
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
4
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...
2
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...
5
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; ...
1
by: niteshpanchal | last post by:
Hi, I want to assign array of 5 using pointer. How can i ?
1
by: niteshpanchal | last post by:
Hi, How to assign dynamic array using pointers for string.
2
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...
2
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...
3
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
1
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)...
1
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...
1
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....
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.