I have some problems:
- How can I erase a file?
- How can I create a random string has 8 letters?
This is my code to create a random string has 8 letters:

char    *b="";
    int        i,j;
    FILE    *f=fopen(file,"w");
    for(i=0;i<4;i++)
    {       for(j=0;j<7;j++)
             *b+=char(random(27)+65);
             fprintf(f,"%s\n",&b);
    }    
    fclose(f);

But the result is wrong
Thank you!

One huge problem is pointer b only points to a one-byte empty string which can not be expanded. Since you want a string of 8 characters then you have to allocate memory for it something like this char b[9] = {0}; . That will allocate memory for 8 characters plus a null terminator, and initialize all of them with 0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.