你可以使用一個隨機數發生器(下面的例子),我覺得ASCII可打印字符在33開始,在127結束,從-1到-95
#include <stdlib.h>
#include <stdio.h> //only for printf
#define RANDINT(r) ((int)(r * (float)random() /(float)RAND_MAX + 0.5))
#define OFFSETRANDINT(r,o) (RANDINT(r) + o)
#define RANDINTX2Y(x,y) (OFFSETRANDINT((y-x),x))
int main(){
srandom(time(NULL)); // important to call this first, but only once
printf("%d\n",RANDINT(2147483647)); //a random int between 0 and 2147483647
printf("%d\n",OFFSETRANDINT(10,10)); //starting @ 10 with a range of 10 (10-20)
printf("%d\n",RANDINTX2Y(0,10)); //between 0 and 10
}
你可能需要轉換INT到(字符),以便您可以將其存儲在一個字符串中
然後您可以使用strstr或strcasestr,具體取決於是否大小寫 只是strcat每個字符串到「乾草堆」,如果它返回! TRUE
#include <string.h>
char *strstr(const char *haystack, const char *needle);
char *strcasestr(const char *haystack, const char *needle);
爲什麼這聽起來像家庭作業懷疑? – 2012-03-03 05:47:11
我保證它不是,但對於我的生活,我不記得我爲什麼問這個 – Lucretiel 2012-06-18 01:38:25