Help - Search - Members - Calendar
Full Version: Programming Question C
Boostcruising.com > Computers and Technology > Tech Head Corner
3000GTCapri
Hi,
Im trying to learn to c programming via just reading some internet tutorials.
I am trying to create a program to control the data and status ports of ltp1.

I have all that down pat, but I want my program to run a function, when the program initializes, (It locates the address vaue of LPT1 port).

Is it possible to make the result of that function available globally, for other functions to use.

void config ()
{
unsigned int far *addresspoint;
unsigned int address;
addresspoint=(unsigned int far *)0x00000408;
clrscr();


address = *addresspoint;
printf("Address: 0x%X \n",address);

printf("\n");
printf("Press Any Key to go back to the Menu\n");
getch();
menu();
}


I would Like to use the value of address in other functions, on a global scale.


void output ()
{
outportb(address,0x00);
delay(100);
outportb(address, 0x01);
printf("\n");
printf("Press Any Key to go back to the Menu\n");
getch();
menu();
}

Basically, Id like to run config () first then make the address value available to the output () function.

Any help would be great, also does anyone know any comprehensive c programing books?
Also yes I know, that you can't directly control the port registers in WindowsNT bases systems, must be 98 or before.
kit
Just declare your variable as global (outside your function/main() call, below your includes) and reference it from your function? or even more appropriate (rather than having functions writing to global variables willy-nilly) is create a separate function to set the address.

#include <mystuff>

unsigned int address;

int setAddress()
{
*set address stuff here*
return address;
}

void main()
{
address = setAddress();
}
kit
http://gd4.tuwien.ac.at/languages/c/progra...brown/c_046.htm

That will get you going in the direct direction (google wins again)
3000GTCapri
thanks kit, ill give it ago.
And i googled for ages, and I thought I could do it like that but wasn't sure of the syntax.
cheers again
kit
My pleasure!
3000GTCapri
thats mate, your a champ.
got it working like a charm.
I was going about it the wrong way.
Trying to make the function output the variable, where as i should have made the variable run the function.
kit
Spot on.

the function still returns the variable however you just set it using a direct assign.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.