Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 how to write empty array?, password programming

views
     
geekster129
post Nov 11 2010, 08:39 PM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



QUOTE(ikanmasin @ Nov 11 2010, 07:59 PM)
hi all,
i am programming a chip using MPLAB HI-TECH, but stuck with the empty array.
well, the program started with i declare an array to store the password, if the array is empty then the key in password will set as password.. now my problem is how to write to know the array is empty?

partial of my programming

unsigned char keyin_char[4];      //declare an 4 values for receiving password
unsigned char stalled_char[4];    // declare an 4 values password array to store the password like this correct?
if(stalled_char[4]="NULL")          // problem starts here, how to write IF array is empty then first keyin_char send to first stalled_char
{
password_count=0;
(keyin_char[0]=stalled_char[0]);
(keyin_char[1]=stalled_char[1]);
(keyin_char[2]=stalled_char[2]);
(keyin_char[3]=stalled_char[3]);
(keyin_char[4]=stalled_char[4]);
(keyin_char[5]=stalled_char[5]);
}

thanks all
*
First of all, stalled_char[4] represents a byte (character) in the stalled_char array.

Secondly, if memory serves me well, if you write out the value of stalled_char[4] if it's null, it should return 0 (as in the ASCII code), I may be wrong.

Have you tried to use strcmp function?
geekster129
post Nov 11 2010, 08:52 PM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



QUOTE(ikanmasin @ Nov 11 2010, 08:45 PM)
er... heard bout it before but how use tat fuction? sry noobie and newbie in programming
*
#include <string.h>

strcmp(char *a,char *b);

returns 0 if a=b
returns negative value if length of a<b
returns positive value if length of a>b
geekster129
post Nov 11 2010, 09:40 PM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



QUOTE(ikanmasin @ Nov 11 2010, 09:26 PM)
after return then? wat i wanted is to check whether the array is empty or not.. because when a number keys in, then the array is not empty rite.. so how to check?
*
strcmp(a,"");

If return value is 0 then it a is a null value, otherwise, a is not a null value.

 

Change to:
| Lo-Fi Version
0.1542sec    0.62    6 queries    GZIP Disabled
Time is now: 18th December 2025 - 08:18 PM