이번 포스트는 fopen을 하였을 때, file의 path를 설정하는 부분입니다.
#include <stdio.h>
int main(void)
{
/* where to write */
const char filepath[] =
"/var/streaming/playlists/chunkcombined/chunkcombined.playlist";
/* what to write */
const char output_lines[] =
"\"/usr/local/movies//chunk0.mp4\" 1\n"
"\"/usr/local/movies//chunk1.mp4\" 1\n"
"\"/usr/local/movies//chunk2.mp4\" 1\n"
"\"/usr/local/movies//chunk3.mp4\" 5\n"
"\"/usr/local/movies//chunk4.mp4\" 5\n";
/* define file handle */
FILE *output;
/* open the file */
output = fopen(filepath, "wb");
if(output == NULL) return -1; /* fopen failed */
/* write the lines */
fputs(output_lines, output);
/* close the file */
fclose(output);
return 0;
}
This version retrieves the text line given as argument to the program and then writes it to desired file:
#include <stdio.h>
int main(int argc, char *argv[])
{
if(argv[1] == NULL) return -1; /* no arguments, bail out */
/* where to write */
const char filepath[] =
"/var/streaming/playlists/chunkcombined/chunkcombined.playlist";
/* define file handle */
FILE *output;
/* open the file */
output = fopen(filepath, "wb"); /* change "wb" to "ab" for append mode */
if(output == NULL) return -1; /* fopen failed */
/* write the lines */
fputs(argv[1], output);
putc('\n', output);
/* close the file */
fclose(output);
return 0;
}
Example:
./write "\"Hello, World!\""
writes: "Hello, World!"
to:
/var/streaming/playlists/chunkcombined/chunkcombined.playlist
.
'소프트웨어' 카테고리의 다른 글
[curl] curl_easy_getinfo (2) (0) | 2014.01.21 |
---|---|
[curl] curl_easy_getinfo (1) (0) | 2014.01.21 |
[ubuntu] T440P NVIDIA 드라이버 잡는 방법(bumblebee) (0) | 2014.01.06 |
[ubuntu]bumblebee 2차 시도 (0) | 2014.01.03 |
[ubuntu] oracle java install 설치 (0) | 2014.01.03 |