As a simple approach, you could write a text file with just one word per line, then read the words into an array, eventually shuffling the array itself, e.g.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_WORDS 1000
#define MAX_LEN 256
void shuffle(char * pword[], int words, int iterations)
{
int n;
if ( words <= 1) return;
for (n=0; n<iterations; n++)
{
int i1, i2;
i1 = rand()%words;
i2 = rand()%words;
char * tmp = pword[i1];
pword[i1] = pword[i2];
pword[i2] = tmp;
}
}
int main()
{
int n;
char buf[MAX_LEN];
char * pword[MAX_WORDS];
int words = 0;
FILE * fp = fopen("words.txt", "r");
if ( ! fp ) return -1;
while (!feof(fp))
{
if (words == MAX_WORDS) break;
if (! fgets(buf, MAX_LEN, fp) ) break;
buf[strlen(buf)-1] = '\0'; pword[words] = strdup(buf); words++;
}
fclose(fp);
shuffle(pword, words, 2*words);
for (n=0; n<words; n++)
printf("%s\n", pword[n]);
for (n=0; n<words; n++)
free( pword[n]);
return 0;
}
The above program reads the file:
aaaaaaaaaaa
bbbbbbbb
cccccccccc
dd
eeeeeeeeeee
fffff
gggggggggggg
hhhhhhhhh
iiiiiiiiiii
jjjjjjjjjj
k
llllllllll
mmmmmmmm
nnnnnnn
ooooooo
p
qqqqqq
rrrrrrrr
sssss
tt
uuuuuu
vvvvvvv
wwwwwww
xxxxxxxxx
yyyyyyyyyyy
z
Producing the following output:
jjjjjjjjjj
aaaaaaaaaaa
rrrrrrrr
fffff
cccccccccc
sssss
qqqqqq
llllllllll
bbbbbbbb
nnnnnnn
uuuuuu
xxxxxxxxx
iiiiiiiiiii
hhhhhhhhh
eeeeeeeeeee
z
dd
k
wwwwwww
tt
mmmmmmmm
vvvvvvv
yyyyyyyyyyy
p
gggggggggggg
ooooooo