Code:
#include<stdio.h>
#include<string.h>
int main (int argc, char *argv[]) {
char folderPath[1024];
int i = 0;
for (i; i < (strlen(argv[0]) - 7); i++) {
folderPath[i] = argv[0][i];
}
printf("Command: afplay %ssong.mp3\n", folderPath);
system("afplay %ssong.mp3", folderPath);
return 0;
}
All Output:
Command: afplay /Users/carloabelli/Desktop/FUNNY/song.mp3
Error: AudioFileOpen failed (-43)
When I run the command from terminal it works perfectly. I was wondering what is going wrong.
system()does not use a format string. It takes the whole command as a literal string. Usesprintf()to format your command into a buffer and then send that buffer to system.or something along these lines.