Ok here is my problem:
I have a bunch of strings like this:
unsigned char hello[]="hello";
unsigned char goodbye[]="goodbye";
Now I have a struct with different values in it:
typedef struct
{
unsigned char **phrase;
//more values are in the actual program
}Greetings;
I wanna sent it to a function that loads in the strings one by one. So I could for example use this:
InitGreetings(&phrases, hello, goodbye);
So far I have this but it does not work:
Code:
void InitGreeting(Greetings *tempGreets, unsigned char *tempPhrase,...)
{
int loop;
unsigned char *s;
tempGreets->phrase=(unsigned char **)malloc(sizeof(unsigned char*) *2);
va_list ap;
va_start(ap, *tempPhrase);
for(loop=0; s=va_arg(ap, unsigned char*); loop++)
{
tempGreets->phrase[loop]*s;
printf("%s", s);
}
va_end(ap);
}
Only thing that happens is the second one is displayed but not the first. The first one prints weird things no matter what string.
Here is the code if you wann look at it:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdarg.h>
#include <stdlib.h>
typedef struct
{
unsigned char **phrase;
//more values are in the actual program
}Greetings;
Greetings phrases;
void InitGreeting(Greetings *tempGreets, unsigned char *tempPhrase,...);
unsigned char hello[]="hello";
unsigned char goodbye[]="goodbye";
int main()
{
InitGreeting(&phrases, hello, goodbye);
getch();
return 0;
}
void InitGreeting(Greetings *tempGreets, unsigned char *tempPhrase,...)
{
int loop;
unsigned char *s;
tempGreets->phrase=(unsigned char **)malloc(sizeof(unsigned char*) *2);//this is different in real program but its close enough
va_list ap;
va_start(ap, *tempPhrase);
for(loop=0; s=va_arg(ap, unsigned char*); loop++)
{
tempGreets->phrase[loop]*s;
printf("%s", s);
}
va_end(ap);
}
There could be some typos but you get the point.