> printf("Type in the name of the app\n");
> fflush(stdin);
> fgets(applic, 15, stdin);
> sprintf(applic2, "\"%s\"", applic);
1. Remove ALL your fflush(stdin), it's undefined, and on any unix system it does nothing (at best) on an input stream.
2. Use fgets() with a large temporary buffer, not a short final result.
3. In this instance, you'll be wanting to remove the newline from the end of the line, which fgets stores.
Code:
char buff[BUFSIZ];
printf("Type in the name of the app\n");
fgets(buff, sizeof buff, stdin);
{ char *p = strchr(buff,'\n'); if ( p ) *p = '\0'; } /* delete the newline, if present */
strncpy( applic, buff, sizeof applic ); /* safe copy of user input */
applic[sizeof applic - 1] = '\0'; /* make sure it's a valid string */
sprintf(applic2, "\"%s\"", applic);
But you could do the whole thing in one call, say
Code:
sprintf( empty2, "open -a \"%s\".app", applic );
But shouldn't the .app be inside the double quotes?