I was trying to get array updated through a function as in below code and this works fine.
char bookCategory[][MAX_CATEGORY_NAME_LENGTH] = {"Computer", "Electronics", "Electrical", "Civil", "Mechnnical", "Architecture"};
uint8_t getCategoryNumAndName(char* catName, uint8_t choice)
{
choice = choice - 0x30 - 1; /** Category starts from 1 on the screen */
if (choice >= (sizeof (bookCategory) / sizeof (bookCategory[0])))
{
//catName = NULL;
return (0xff);
}
else
{
strcpy(catName,bookCategory[choice]);
//catName = bookCategory[choice];
return(choice);
}
}
void addBooks(void)
{
// Some code here
char categoryName[30];
uint8_t catNumber;
catNumber = getCategoryNumAndName(categoryName, choice);
// Some code here
}
But I thought of making use of double pointer instead of using strcpy(). I tried below code, but I get incompatible pointer type error. How to call getCategoryNumAndName() in below code from addBooks()?
uint8_t getCategoryNumAndName(char** catName, uint8_t choice)
{
choice = choice - 0x30 - 1; /** Category starts from 1 on the screen */
if (choice >= (sizeof (bookCategory) / sizeof (bookCategory[0])))
{
*catName = NULL;
return (0xff);
}
else
{
//strcpy(catName,bookCategory[choice]);
*catName = bookCategory[choice];
return(choice);
}
}
void addBooks(void)
{
// Some code here
char categoryName[30];
uint8_t catNumber;
catNumber = getCategoryNumAndName(&categoryName, choice);
// Some code here
}