To remove file using rm inside c

Unixians,

I need one help,I have to remove a file from particular path.

see my code snippet,

 {
 char cmd[100]="";
 sprintf (cmd, "/bin/rm -f %s%s%s%s","/usr1/mydir/", 1.t,2.t,3.t);
 system(cmd);
 }

The problem is it read as a "/usr1/mydir/1.t2.t3.t" and no files is removed.
Can u plz provide the solution.
Thanks in advance.

Is there a reason you are not using the unlink system call? Also, I am unfamiliar with the 1.t , etc constructs, can you explain what this does, or what you are expecting it to do?

Can't you give *.t or are there many files with .t as extension?

Friends,

The problem in removing is the string read like this /usr1/mydir/1.t2.t3.t.
My requirement is to remove file 1.t,2.t and 3.t .
The path is same only file name is different.

The files removed like this
rm -f /usr1/mydir/1.t
rm -f /usr1/mydir/2.t
rm -f /usr1/mydir/3.t

Please help on this.

char cmd[100]="";
    printf("%d\n", chdir("/usr1/mydir/"));
    sprintf (cmd, "/bin/rm -f %s,%s,%s","/usr1/mydir/", "1.t","2.t","3.t");
    system(cmd);

Its still having same issue.
I just print the string ,now its looks /bin/rm -f /usr1/mydir/1.t,2.t,3.t.
No removal is done.
sprintf (cmd, "/bin/rm -f %s,%s,%s","/usr1/mydir/", "1.t","2.t","3.t");

The contents of cmd, after the [man]sprintf[/man] would be: /bin/rm -f /usr1/mydir/,1.t,2.t , which is not what is needed to remove a file. This does what you want:

{
    char path[100];
    char *file[3] = { "1.t", "2.t", "3.t"; }

    for (int i = 0; i < 3; i++) {
        strcpy(path, "/usr1/mydir/");
        strcat(path, file);
        unlink(path);
    }
}

Although there is no error checking what-so-ever.

Thank you all,
Now its working fine:)
I also tried like this that also working.
sprintf (cmd, "/bin/rm -f %s%s %s %s","/usr1/mydir/", "1.t","2.t","3.t");