0

I want to execute the following commands from a C program:

amixer --quiet set Master 5+
amixer --quiet set Master 6-

Here, 5 and 6 are not fixed values. They are Input Arguments of the code which can have different values.

Can anybody please guide me on how to achieve this?

4

2 回答 2

1

Did you try:

system("amixer --quiet set Master 5+");
system("amixer --quiet set Master 6-");
于 2012-08-26T12:27:01.993 回答
0

The following code can achieve this:

#include <stdio.h>
#include <stdlib.h>     /* For system() */

#define SIZE 28

int main()
{
    char action;
    unsigned int level;

    char CommandString[SIZE];

    printf ("\nTo Increase\\Decrease volume press 'i'/'d': ");
    scanf  ("%c", &action);

    if (action!='i'&& action !='d')
    {
        printf ("\nInvalid Choice, please try again\n");
        main();
    }

    printf ("\nEnter Voice Change Level: ");
    scanf  ("%u", &level);

    if (action=='i')
    {
        printf ("\nIncreasing Voice level by: %u\n", level);
        sprintf (CommandString, "amixer --quiet set Master %d+", level);
    }
    else
    {
        printf ("\nDecreasing Voice level by: %u\n", level);
        sprintf (CommandString, "amixer --quiet set Master %d-", level);
    }

    system (CommandString);

    return 0;
}
于 2012-08-26T12:27:51.303 回答