The user enters how many characters the password must be made of, then clicks a
ID: 3693866 • Letter: T
Question
The user enters how many characters the password must be made of, then clicks a Generate button. The output is then a string made of numbers, letters (some of are upper case and some are lower case) along with any other characters you wish to use. The code must use a For loop and no other type of loop. The code must also use the Chr string functions, along with the Random function. The Random function generates a number (you need to figure out the range). The number generated is then used in the Chr function as the ASCII value to generate a character. The code must randomize using a letter, upper case or lower case, a number or some other characters.
Explanation / Answer
#include <stdio.h>
#include<stdlib.h>
int main() {
int len,value,top=0,i;
char *str;
printf("ENter the length of the password ");
scanf("%d ",&len);
str=(char *)malloc(len*sizeof(char));
for(i=0;i<len;)
{
value= rand() % 122;
printf("value is %d ",value);
if(value+48<122){
str[top]=value+'0';
printf("strtop is %c ",str[top]);
top++;
i++;
}
}
printf("%s isstring ",str);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.