0

Here's the code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
char __rand_char(){
    srand(time(0)); 
    char *l="abcdefghijklmnopqrstuvwxyz";
    return l[rand() % 26];
}
void randomize(char *str){
    register int counter=0;
    while(*(str+counter++)!='\0'){
        *(str+counter)=__rand_char();
    }
}
int main(void){
    char str[12];
    memset(str,0,sizeof(char)*12/sizeof(char));
    str[11]='\0';
    char cmpstr[]="Hello World";
    while(strcmp(cmpstr,str)!=0){
        randomize(str);
        puts(str);
        sleep(1);
    }
    return 0;
}

Now, yes. Some people might be thinking the primary while loop is basically infinite but that's not where the problem lies. In the function __rand_char(), I literally can't print a character pointer . I think the character pointer l is faulty. I can't print it or its length. Why? The compiler does not complain even with -Wall but when I execute it, __rand_char doesn't work.

0 Answers0