string - How to create a file with random char in C? -
i have no problem in generate random numbers rand() have create output file string of char e.g. "aqsdjeiofhduk" when result of rand ()%26 +1 1 i've print in file "a" when result "2" b , on. know priori how many char in string let's 50. i've in c language. function should use? strcat?
simple set array random letters selected via rand()
#define random_string_length 50 char buf[random_string_length + 1]; (size_t = 0; < random_string_length; i++) { buf[i] = "abcdefghijklmnopqrstuvwxyz"[rand() %26]; } buf[random_string_length] = '\0'; puts(buf);
Comments
Post a Comment