On Sat, 2 May 1998, Ibrahim Haddad wrote:
> Hello all,
>
> I have a slight problem.
> I am checking if a structure variable is empty to display a warning window
> (with
> motif) and if the variable holds a value (file name), I want to go ahead and
> delete the file using a system call to "rm -f"
>
> My code:
> --------
> if (strcmp(castedPtr->tname, "") == 0)
> /* check if string is empty and display warning message */
> missingInputCB (w, clientData, callData);
> else /* delete file name that matches the value of castedPtr->tname */
> system("rm -f castedPtr->tname");
>
> However, system("rm -f castedPtr->tname")
> is not working because the rm command will be searching for a file called
> castedPtr->tname to delete it while in fact this pointer holds the file name.
>
> Is there a way to get around this?
>
> Thank you in advance.
>
> - Ibrahim
>
Um. Maybe you've been using perl too much lately.
Try the following.
#include <strings.h>
if (strcmp(castedPtr->tname, "") == 0)
/* check if string is empty and display warning message */
missingInputCB (w, clientData, callData);
else { /* delete file name that matches the value of castedPtr->tname */
char *command = (char*)malloc(strlen(castedPtr->tname)+6);
if (!command) {
crash_and_burn();
}
strcpy(command, "rm -f");
strcat(command, castedPtr->tname);
system(command);
free(command);
}
Something to that effect should work.
Pete
Pete Ryland Home phone: +61 2 9697 9262 Mobile: 014 035 802
email: [EMAIL PROTECTED] ICQ UIN: 4256333
WWW: http://www.pdr.ml.org ftp: ftp.pdr.ml.org