This program should generate n*2 random characters and insert them into a linked list. The problem is that, even if random characters are generated, the linked list is composed by numbers, I can't understand why. Thanks for helping.
struct node{
char *string;
struct node *next;
};
void display(struct node *head){
struct node *tmp;
tmp = head;
while(tmp!=NULL){
printf("%d\t", tmp->string);
tmp = tmp->next;
}
}
struct node* front(struct node *head, char c) {
struct node *p;
p = malloc(sizeof(struct node));
p->string = c;
p->next = head;
return(p);
};
int main() {
struct node *l;
int n, i, op;
char c;
do{
printf("digit an integer >1: ");
scanf("%d",&n);
if(n<1){
printf("the integer must be >1: ");
}
}while(n<1);
l = malloc(sizeof(struct node));
l = NULL;
for(i=0;i<(2*n); i++) {
char c = 'A' + (rand() % (126 - (33) + 1) - (-1));
l = front(l, c);
};
display(l);
return 0;
};
Aucun commentaire:
Enregistrer un commentaire