Greetings and welcome to my first post. My objective is to generate 1000 random strings of lowercase letters of random length 3-9, and write them to a file. It seems like I've accomplished all of this, but there's a problem.
It looks like whenever a random 9-character string is generated/printed, it has this [*little box*]« at the end.
Example: mkpvcq xicleyjip[*little box*]« abqwn lmpjgswtq[*little box*]«
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(){
int i = 0, j = 0;
int numWords = 1000;
int length;
FILE *fout;
fout = fopen("words.txt","w");
for( i = 0; i < numWords; i++ ){
length = (3 + rand() % 7);
char word[length];
for( j = 0; j < length; j++ ){
word[j] = 'a' + (rand()%('z'-'a'));
}
fprintf(fout, "%s ", word);
memset(word, 0, length);
}
fclose(fout);
return 0;
}
(t is required that they are saved as strings before being written to the file, not just put directly as individual characters)
How do I fix this? Thanks.