|
|
View previous topic :: View next topic |
Author |
Message |
mugheesahmed
Joined: 12 Jun 2006 Posts: 9
|
CAN'T PASS BACK AN ARRAY..!!! |
Posted: Mon Jul 17, 2006 1:01 am |
|
|
okay im doing this.... ->
--------------------
[code]char* KP_gets()
{
int l=-1;
char ch[8];
do
{
l++;
do
{
ch[l]=kbd_getc();
fputc(ch[l],serial);
}while(((ch[l]<'0')||(ch[l]>'9'))&&(ch[l]!='*')&&(ch[l]!='#'));
}while(ch[l]!='#');
ch[l]='\0';
return ch;
}
void main()
{
char *option, *pswd;
option=KP_gets();
puts(option)
pswd=KP_gets();
puts(pswd);
}[/code]
program OUTPUT:
1234567
1234567
7654321
�ს
---------------------------------------------
(i've just showed a ruff outline of wat im really doin here)
the problem i'm facing is that my program although is taking correct input but when it outputs the results it shows that pswd was not correctly passed back from the fuction..at least this is wat i think the problem really is...so it is not showing the results correctly...however the string option is displayed correctlly....
PLEASE REPLY SOON...NEED UR HELP PEOPLE..[code][/code][code][/code][code][/code][code][/code]
Last edited by mugheesahmed on Mon Jul 17, 2006 1:23 am; edited 2 times in total |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Jul 17, 2006 1:08 am |
|
|
It too hard to read your code. Use the code button. Edit your post and put (replace the word codxx in the following with the word code) [codxx] before the start of your code and [/codxx] after the end of your code. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah Guest
|
|
Posted: Mon Jul 17, 2006 2:26 am |
|
|
You probably need to make the array _static_.
The problem is that a variable, is only guranteed to 'exist' for as long as the function creating/dealing with it exists. If you handed the _array_ back, then the compiler would generate a copy to keep alive, but if you hand back a pointer to an array, the compiler does not know that the array should be protected from re-use. Hence variables used this way, need to have the static declaration, to tell the compiler to protect the RAM space
Seperately though, I can see no sign of any attempt to ensure that your data does not overflow the allowed area. For safety, add a limit to the values that 'l' can take. When you increment it, if it is >7, then set it back to 7 (or implement some other more complex limitation algorithmn). Otherwise this will 'bite you' at some point, when noise introduces an extra character, or some similar problem appears.
Best Wishes |
|
|
Guest
|
|
Posted: Mon Jul 17, 2006 11:04 pm |
|
|
THANKS ALOT DUDE....
I JUST CANT FIGURE IT OUT WHY I DIDNT THINK OF THAT BEFORE...MAY BE THE LACK OF PRACTICE...
NEWAYS...YOUR SUGGESTION REALLY HELPED ME AND THE PROBLEM WAS SOLVED...THANKS AGAIN...
BUBYE... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|