/* defines.h */
/* for defines about board */
#ifndef CBOARD_DEFINE_
#define CBOARD_DEFINE_
#define MAX_ENTRY 255
const char *title_file = "title.cdb";
const char *temp_file = "cdb.tmp";
#endif
/* for defines about board */
#ifndef CBOARD_DEFINE_
#define CBOARD_DEFINE_
#define MAX_ENTRY 255
const char *title_file = "title.cdb";
const char *temp_file = "cdb.tmp";
#endif
/* main.c */
#include "defines.h"
#include
int insert_title(char *title);
void list_title(void);
int remove_title(char *title);
void process(void);
int main (int argc, char **argv) {
process();
return 0;
}
void process (void) {
}
int insert_title(char *title) {
FILE *fp = fopen(title_file, "a");
if (!fp) return -1;
else {
fprintf (fp, "%s
", title);
fclose(fp);
}
return 1;
}
int remove_title(char *tmp_title) {
FILE *title_fp, *temp_fp;
char entry[MAX_ENTRY];
char title[MAX_ENTRY];
if (tmp_title[0] == '?') return 1;
strcpy (title, tmp_title);
strcat (title, "
");
title_fp = fopen(title_file, "r");
if (!title_fp) return -1;
temp_fp = fopen(temp_file, "w");
if (!temp_fp) return -2;
while ( fgets(entry, MAX_ENTRY, title_fp) ) {
if (strcmp (title, entry))
fputs (entry, temp_fp);
}
fclose(title_fp);
fclose(temp_fp);
unlink(title_file);
rename(temp_file, title_file);
}
void list_title(void) {
FILE *title_fp;
char entry[MAX_ENTRY];
title_fp = fopen(title_file, "r");
if (!title_fp) return;
while ( fgets(entry, MAX_ENTRY, title_fp) )
printf ("%s", entry);
}
#include "defines.h"
#include
int insert_title(char *title);
void list_title(void);
int remove_title(char *title);
void process(void);
int main (int argc, char **argv) {
process();
return 0;
}
void process (void) {
}
int insert_title(char *title) {
FILE *fp = fopen(title_file, "a");
if (!fp) return -1;
else {
fprintf (fp, "%s
", title);
fclose(fp);
}
return 1;
}
int remove_title(char *tmp_title) {
FILE *title_fp, *temp_fp;
char entry[MAX_ENTRY];
char title[MAX_ENTRY];
if (tmp_title[0] == '?') return 1;
strcpy (title, tmp_title);
strcat (title, "
");
title_fp = fopen(title_file, "r");
if (!title_fp) return -1;
temp_fp = fopen(temp_file, "w");
if (!temp_fp) return -2;
while ( fgets(entry, MAX_ENTRY, title_fp) ) {
if (strcmp (title, entry))
fputs (entry, temp_fp);
}
fclose(title_fp);
fclose(temp_fp);
unlink(title_file);
rename(temp_file, title_file);
}
void list_title(void) {
FILE *title_fp;
char entry[MAX_ENTRY];
title_fp = fopen(title_file, "r");
if (!title_fp) return;
while ( fgets(entry, MAX_ENTRY, title_fp) )
printf ("%s", entry);
}
'Coding > Tip' 카테고리의 다른 글
Float 를 비트로 보여주기 (0) | 2005.05.05 |
---|---|
SLAX Live Linux 네트워크 설정법 (0) | 2005.04.13 |
한글버전 MSDN (0) | 2005.03.11 |