looking for some solutions? You are welcome.

SOLVED: Get both a char and a integer as input OR just a char as input

Bret Hasel:

Working on a c knapsack program that will have a UI like interface, ive come to a point where i need for the user to be able to enter in characters for commands and while all of the ones which require only a simple one character input are quite simple i need to be able to allow the user to enter in a char and an int at the same time in the cases of adding or removing a number from the knapsack. While i know this can be done with two separate inputs from the user i'm wondering how can this be done in the same line without requiring the user to enter in two separate inputs. Example being the user types >a 7 then it will add 7 to the knapsack.


#include <stdio.h>
#include "knapsack.c"
#include <stdlib.h>
#include <string.h>

int main()
    listitemptr k2 = NULL;
    char input[100], ;
    int returnval;
    while(*input != 'q'){
        printf("> ");
        scanf("%s", input);

        if(*input == 'p'){


Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots

No comments: