Question:
C Programming: "Too many arguments to function 'system'.?
Cluck Cluck
2010-04-14 06:24:48 UTC
So far, the code is:

char request;

printf("Select track\n\n");
scanf("%s", request);

system("mplayer %s", request);

But it says "Too many arguments to function 'system'.

Thanks!
Three answers:
?
2010-04-14 07:03:40 UTC
system() accepts a single argument, which is the command to be executed.



What you should do is:



char system_str[256];

snprintf( system_str, 256, "mplayer %s", &request );

system( system_str );



If you want a little more advice, note that your program could be a huge security problem, if it is running at a different level of access than the user. Imagine if when requested to select track, the user types in "; rm -rf /".



Typically, system() is not the best command to use. Better, and much safer, to use fork() and execl(), although that's a bit more complicated.



Your scanf() is also incorrect. You are trying to store a string (multiple byte array terminated by a null character) in a single character.



You should instead use an array

char request[256];



But you also need to abandon scanf, since it is unable to prevent buffer overflows (that is, the user enters more than 255 characters).



Better to do this:



char request[256];

fgets( request, 256, stdin );



That will at least avoid buffer overflows. You should also have error checking code which deals with the return values of all of these functions.
maull
2016-12-17 11:41:21 UTC
initially, why are you putting forward false_positives as glide while you're in straight forward terms returning an int fee from the function? As for the too few arguments: once you declare your function (2d line) you're actually not meant to furnish the variables names. So your function ought to be: int flase_positives(int, glide, glide) additionally i decide for to advise against utilizing a similar call for a value and a function call, as a results of fact it may get confusing in larger courses and it may become a foul habit.
Lav
2010-04-14 20:39:09 UTC
char request takes only one variable of type character...

so declare it as a array say char request[size]....


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...