파일 시스템 호출 사용

파일 시스템 호출 사용

파일 열기, 쓰기, 닫기를 위한 시스템 호출을 배우려고 합니다. 이 예를 사용했는데 결과는 다음과 같습니다.

gcc: error trying to exec 'cc1plus': execvp: No such file or directory

이것은 내 프로그램입니다:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

int main (int argc, char *argv[])
{
    int fd1;
    char buf[128];
    fd1 = open("Desktop/this.txt", O_WRONLY);
    if (fd1 == -1) {
        perror("File cannot be opened");
        return EXIT_FAILURE;
    }

    /* Enter the data to be written into the file */
    scanf("%127s", buf);

    write(fd1, buf, strlen(buf)); /* fd1 is the file descriptor, buf is the character array used to
 hold the data, strlen(buf) informs the function that the number of bytes equal to the length of the
 string in the buffer need to be copied */

    close(fdl);

    return 0;
}

답변1

나는 당신이 Ubuntu, Debian 또는 일부 파생 제품을 사용하고 있다고 가정합니다. 시스템이 최신인지 확인한 다음 g++를 설치하세요.

답변2

cc1plusC++ 컴파일러의 구성 요소입니다. C 프로그램을 컴파일하려고 합니다. 이 gcc명령은 소스 파일의 이름(C 컴파일러, C .c++ 컴파일러, 파스칼 컴파일러, 어셈블러 등)을 기반으로 호출할 컴파일러를 결정합니다..cc.C.p.s

프로그램에 C++ 프로그램을 나타내는 이름을 지정한 것으로 보입니다. Linux 파일 이름은 대소문자를 구분합니다. C 소스 파일은 확장자 .c(소문자 c)를 가져야 합니다 .C. Unix 사용자는 특히 거의 모든 일반 파일 확장자가 소문자이기 때문에 파일 이름에 대부분 소문자를 사용하는 경향이 있습니다. 따라서 파일 이름은 소문자로 사용해야 합니다.

관련 정보