求助,如何读取用户的不同类型输入
我在做红黑树相关的作业时,被要求读取一连串数字,最后输入“x”停止输入并打印整个树。这是我在github上学(抄)到的一种读取方式,但是只能读取一位数,想问下有没有别的比较好的读取方式,然后求这种读取方式有没有能读整个输入的
char *input = malloc(sizeof(char) * 255 * 2);
char *token = NULL;
RBRoot *root=NULL;
root = create_rbtree();
while(true){
printf("Please Enter A Number To Insert: ");
if(fgets(input)){
token = strtok(input, " \n"); //read the user command and check for which operator
*token = toupper(*token);
if(strcmp(token, "X") == 0){
printf("stop entering and printing the output...\n");
printf("In-order traversal of the tree: ");
inorder_rbtree(root);
break;
}else{
insert_rbtree(root, *input-'0');
} RBRoot是什么类型? howzyao 发表于 2020-4-8 19:41
RBRoot是什么类型?
typedef struct RBTreeNode{
unsigned char color; //red or black
Type key; //key
struct RBTreeNode *left; //left child
struct RBTreeNode *right; //right child
struct RBTreeNode *parent; //parent
}Node, *RBTree;
typedef struct rb_root{
Node *node;
}RBRoot; 换字输入,试试,不输入10 20 30输入123 333 555
页:
[1]