Does anyone know how to stor character by character into a array?
That mean, in beginning the contain inside array is empty, when a user keying a number/alphabet, i need to stor the number/alphabet into the array.
Here is my program,but when i complie,it give me some warning...like this <assign far pointer to near pointer,bank value ignored>, why?
unsigned char *phonebook[20];
unsigned int phone_size=0;
void main()
{....
....
phonebook[phone_size]= "9"; //assume user key in number 9
phone_size++;
....
....
display();
}
void display(void)
{ int i;
for(i=0;i<10;i++)
{
phonebook;
}
}
Does anyone can point out my problem,pls??thanks !!
Your declaration 'char *phonebook[20];' declares an array of 20 pointers to char's. This is commonly called a ragged array.
To populate the array, you need a buffer and something like 'gets(buffer)' to get the input. 'gets()' reads a string up to, but not includung the return.You then need to allocate memory for the string and copy it to your array.
This is not so good, how big should you make the buffer? Some maliscious soul will try to overflow it, and get into your phonebook. Then he can phone up that cute chick with the nice ass that you had your eyes on!