컴퓨터/프로그래밍

C언어 파일 또는 디렉토리 삭제 함수 remove()

2020. 3. 15. 10:42

C함수 파일 또는 디렉토리 삭제 remove()

파일 또는 디렉토리를 삭제합니다.

  • 헤더: stdio.h
  • 형태: int remove(const char *pathname)
  • 인수: char *pathname 삭제할 파일이나 디렉토리
  • 반환: int 0 == 성공, -1 == 실패

C언어 remove() 함수 예제

#include <stdio.h>

int main()
{
   if ( -1 == remove( "a.out"))
      printf( "파일 삭제 실패n");
}

C언어 remove() 예제 실행 결과

]$ ./a.out
]$ ls
test.c  <- 컴파일해서 만들어진 실행파일 a.out이 없습니다.
]$