파일 입출력 질문 있습니다.

Zera의 이미지

#include

int main()
{
int num=0;//번호 select
char object[25]="";//단어 입력 변수
char enter[2]="\n";//개행

FILE *word;//파일 입출력을 하기 위한 설정

//목차 번호 누르고 enter
printf("*Please input only small letter*\n");
printf("1. Animal\n");
printf("2. Transportation\n");
printf("3. Fruit\n");
printf("4 is quit system\n");

while(1)//무한 loop
{
printf("Input the category number : ");

scanf("%d",&num);//num 입력

switch(num){

case 1:
word = fopen("Animal.txt","a+");//a+은 읽기 쓰기 전부 가능한 모드로 open
printf("Input the correct word : ");
scanf("%s",object);//scanf로 먼저 object에 문자열을 overlap
fputs(object,word);//메모장에 입력
fputs(enter,word);//메모장에 개행 입력해서 한줄에 한단어씩 입력되게 하는 것.
fclose(word);
break;
case 2:
word = fopen("Transportation.txt","a+");
printf("Input the correct word : ");
scanf("%s",object);
fputs(object,word);
fputs(enter,word);
fclose(word);
break;
case 3:
word = fopen("Fruit.txt","a+");
printf("Input the correct word : ");
scanf("%s",object);
fputs(object,word);
fputs(enter,word);
fclose(word);
break;

case 4:
return 0;

default :
printf("You input wrong number. Please ");
break;
}
}
return 0;
}

이게 제 소스코드입니다. 파일 입출력으로 데이터를 메모장에 저장하고 불러오고 싶어서 만들었습니다.
여기서 두가지를 추가로 업데이트 하고 싶은데요
첫 번째는 메모장 입력할 때 중복 걸러내기 입니다. 즉 같은 단어를 또 입력하면 프로그램상으로 처리해서 같은 단어가 메모장에 재입력 되는것을 방지시키는 기능이구요.

두 번째는 프로그램을 한번 실행시킨 후 생성된 메모장 란에는 한줄에 단어 한 개가 입력되어있습니다.
그래서 1번이라고 입력하면 첫번째 줄에 있는 단어를 출력하고 2를 누르면 두번째 줄에 있는 단어를 출력하는 코딩을 하고 싶습니다.

파일 입출력에 대해 잘 아시는 분들은 지식을 나누어 주시면 감사하겠습니다. 부족한 저좀 가르쳐 주세요^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.