I am writing a random compliment generator program in C
#include <stdio.h>
int main()
{
int i;
char compliment[3][30] = {"You look so beautiful!", "You are a great person!", "Your hair is so stunning!"};
for(i=0;i<sizeof(compliment)/sizeof(compliment[0]);i++)
{
puts(compliment[i]);
}
return 0;
}
output of this program is:
You look so beautiful!
You are a great person!
Your hair is so stunning!
But I want the compliments to be displayed randomly and just one not all of them. How can I do this? which function should I use?
EDIT: Thanks for comments. I did it:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i;
char compliment[3][30] = {"You look so beautiful!", "You are a great person!", "Your hair is so stunning!"};
srand(time(NULL));
puts(compliment[rand() % 3]);
return 0;
}