I need to get a position using scanf and a string line from the user using fgets but fgets doesn't work
I thought the issue is a \n in the scanf automatically create it after your input
I coded scanf("%i\n", &n) but it still didn't work
int inputPosition(){
int n = -1;
printf("Input a position (you have %i elements):\n", numElements);
while(1){
scanf("%i\n", &n);
if (n < 0 || n > numElements){
printf("Invalid input! Please, try again\n");
} else {
break;
}
}
return n;
}
struct node *newNode(){
struct node *newNode = malloc(sizeof(struct node));
if (newNode == NULL){
printf("malloc's error");
return NULL;
};
printf("input your data:\n");
fgets(*newNode->data, N, stdin);
newNode->prev = NULL;
newNode->next = NULL;
return newNode;
}