리눅스기반 저수준 파일입출력 질문
놀리기
2023.04.01
#include fcntl.h#include stdio.h#include string.h#include sys/stat.h#include unistd.h#include stdlib.hvoid fail_command(char * input){ printf(using %s command \n,input);}int main(int argc, char* argv[]){ int fd=open(/home/hiroo/file/command.txt,o_creat|o_wronly|o_append,s_irusr); int len; char * strptr=(char*)malloc(sizeof(argv[1])+1); if((strlen(argv[0])) 2) { fail_command(argv[0]); return -1; } strcpy(strptr,argv[1]); len=strlen(argv[1]); write(fd,argv[1],len); close(fd); return 0;}
컴파일후 ./a.out hiroo 라고 치면 문자열이 command.txt 에 문자열이 출력되야하는데 안되네요 ..무슨 문제인지 알려주세요 .