Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Moved] need help is solving a problem with Arrays

Status
Not open for further replies.

Naveenk.wins

Newbie level 4
Joined
Jun 2, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
hi,

i have the following definition in a dev.c
const char *Device_Name_a[4] =
{
"Dev0",
"Dev1",
"Dev2",
"Dev3",
};

and in handle.c i have used the above information like this

extern const char *Device_Name_a[];

char *device = Device_Name_a[0];

This is working fine

I need to replace the above using, get_device_name function.
my goal is get the variable(device name) which is declared globally using get function instead of "char *device = Device_Name_a[0];"

can any one help in how to do this?

Its very urgent i have a release by end of day...:cry:
 

I didnt understood....
You need a function that will return those string from the array,or what???
 

hi,

const char *Device_Name_a[4] =
{
"Dev0",
"Dev1",
"Dev2",
"Dev3",
};

const char* get_devicename(unsigned char temp)
{
return(Device_Name_a[ temp ]);
}

in handle.c file

extern const char* get_devicename(unsigned char temp);

local variable:
const unsigned char* devname_p ;

devname_p =get_devicename( 0 );

All i need to check is devnamp_p u should get "Dev0" .

Whats wrong in the above code..
 

I dont think you should have any problems...
Anyway here is how to do it

This code will be in "dev.c" file
Code:
//dev.c

const char *Device_Name_a[4] =
{
"Dev0",
"Dev1",
"Dev2",
"Dev3",
};

const char* get_devicename(unsigned char temp)
{
   return(Device_Name_a[temp]);
}

And this code will be in "handle.c" file
Code:
#include "stdio.h"
#include "stdlib.h"

const char* get_devicename(unsigned char temp);

int main(void)
{
	
    const char * devname_p = get_devicename(0);
    puts(devname_p);
	system("pause");
	return 0;
}

Good Luck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top