Misplaced Pages

Remove (C): Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 18:00, 9 August 2010 editSarekOfVulcan (talk | contribs)Autopatrolled, Administrators51,754 editsm Adding category Category:C programming language (using HotCat)← Previous edit Revision as of 14:51, 22 August 2010 edit undoBiT (talk | contribs)Extended confirmed users, Pending changes reviewers3,958 editsNo edit summaryNext edit →
Line 23: Line 23:
return 0; return 0;
} }
</source>

<code>remove</code> can be used to remove the C executable after it has finished running where </code>]] refer to the number and value of the ]s where <code>argv</code> is the first argument, i.e. the name of the executable:

<source lang="c">
#include <stdio.h>

int main(int argc, *char argv)
{
printf("Now removing the file %s.\n", argv);
remove(argv);
return 0;
}
</source> </source>



Revision as of 14:51, 22 August 2010

remove is a function in C programming language that removes a certain file. It is included in the C standard library header file stdio.h.

The prototype of the function is as follows:

int remove ( const char * filename );

If successful, the function returns zero. Nonzero value is returned on failure and errno variable is set to corresponding error code.

Sample usage

The following program demonstrates common usage of remove:

#include <stdio.h>
int main() {
    const char *filename = "a.txt";
    remove (filename);
    return 0;
    }

remove can be used to remove the C executable after it has finished running where int argc, *char argv refer to the number and value of the command-line arguments where argv is the first argument, i.e. the name of the executable:

#include <stdio.h>
int main(int argc, *char argv)
{
    printf("Now removing the file %s.\n", argv);
    remove(argv);
    return 0;
}
Category: