Hi I'm having trouble returning an 8 char string from a function. I can get the correct value displayed from printf("%c%c%c%c%c%c%c%c \n", bit0 ,bit1 ,bit2 , bit3, bit4, bit5, bit6, bit7); but can't get into a char * to return the string to the calling function. Any help would be greatly appreciated.
My code is below:
Code:
char * GetPassword(void){
char c;
char * password;
char bit0 = '0';
char bit1 = '0';
char bit2 = '0';
char bit3 = '0';
char bit4 = '0';
char bit5 = '0';
char bit6 = '0';
char bit7 = '0';
PORTJ |= (1<<DDJ0)|(1<<DDJ1); // Enables the internal pullups for PORTJ0 and PORTJ1
PORTH |= (1<<DDH0)|(1<<DDH1); // Enables the internal pullups for PORTH0 and PORTH
PORTD |= (1<<DDJ0)|(1<<DDJ1)|(1<<DDJ2)|(1<<DDJ3); // Enables the internal pullups for PORTJ0, PORTJ1, PORTJ2 and PORTJ3
printf("Please Enter Your Password \n");
if ((~PINJ & (0<<PJ1)))
{
bit0 = '0';
}
else if ((~PINJ & (1<<PJ1)))
{
bit0 = '1';
}
if ((~PINJ & (0<<PJ0)))
{
bit1 = '0';
}
else if ((~PINJ & (1<<PJ0)))
{
bit1 = '1';
}
if ((~PINH & (0<<PH1)))
{
bit2 = '0';
}
else if ((~PINH & (1<<PH1)))
{
bit2 = '1';
}
if ((~PINH & (0<<PH0)))
{
bit3 = '0';
}
else if ((~PINH & (1<<PH0)))
{
bit3 = '1';
}
if ((~PIND & (0<<PD3)))
{
bit4 = '0';
}
else if ((~PIND & (1<<PD3)))
{
bit4 = '1';
}
if ((~PIND & (0<<PD2)))
{
bit5 = '0';
}
else if ((~PIND & (1<<PD2)))
{
bit5 = '1';
}
if ((~PIND & (0<<PD1)))
{
bit6 = '0';
}
else if ((~PIND & (1<<PD1)))
{
bit6 = '1';
}
if ((~PIND & (0<<PD0)))
{
bit7 = '0';
}
else if ((~PIND & (1<<PD0)))
{
bit7 = '1';
}
c = getchar();
while (getchar() != '\n');
printf("%c%c%c%c%c%c%c%c \n", bit0 ,bit1 ,bit2 , bit3, bit4, bit5, bit6, bit7);
*(password+1) = bit0;
*(password+2) = bit1;
*(password+3) = bit2;
*(password+4) = bit3;
*(password+5) = bit4;
*(password+6) = bit5;
*(password+7) = bit6;
*(password+8) = bit7;
return password;
}