리눅스 cat 옵션 구현 질문

joon821의 이미지

안녕하세요 오랫동안 풀다가 도저히 다른옵션은 구현을 못하겠어서
이렇게 질문을 드립니다 ㅠㅠ
cat 의 n 옵션은 구현을 했는데 다른 옵션을 구현하고 싶은대 되지 않습니다 . cat의 옵션중 -n 기능 포함해서 3가지를 구현 하고싶은데 도와주실분 ..

#include <stdio.h>
#include <unistd.h> 
void output_file(FILE *fp);
int flag = 0;
main(int argc, char *argv[])
{
 FILE *fp;
 int opt;
 if (argc == 1) { 
 printf("Usage : a.out [-n] filename ...\n");
 exit(1);
 }
 
 while ((opt = getopt(argc, argv, "nbv")) != -1) {
 switch (opt) {
 
 case 'n':
 flag = 1;
 break;
 default:
 printf("unknown option : %c\n", optopt);
 }
 }
 
 if (argc != 2)
 argv++;
 
 while (*++argv) {
 printf("\n[filename : %s]\n", *argv);
 if ((fp = fopen(*argv, "r")) == NULL) {
 perror("fopen failed");
 exit(2);
 }
 output_file(fp);
 fclose(fp);
 }
 exit(0);
}
void output_file(FILE *fp)
{
 int ch, line = 1;
 if (flag)
 printf("1 ");
 while ((ch = getc(fp)) != EOF) {
 if (flag && ch == '\n') {
 
 if ((ch = getc(fp)) == EOF)
 break;
 
 ungetc(ch, fp);
 printf("\n%-4d", ++line);
 }
 else
 putc(ch, stdout);
 }
 
}
 printf("\n");
qiiiiiiiip의 이미지

중간 고사 기간인 모양이네요.

숙제를 묻고 답하는 것에 관한 좋은 글이 있네요.
http://meta.stackexchange.com/a/10812

특히

Make a good faith attempt to solve the problem yourself first. 
Ask about specific problems with your existing implementation. 
Admit that the question is homework. 
Be aware of school policy.
Never use code you don't understand.

는 질문자 입장에서 꼭 지켰으면 좋겠습니다
세벌의 이미지

좋은 말씀이시네요. 그런데 여기 질문 하시는 분들 중엔 영어도 약하신 분이 많으셔요. 그래서... 이렇게 영어로 써 놓으시면...
숙제를 못해서 질문했더니 영어 해석하라고 숙제를 또 내 주네...
라고 생각하실 분도 있을 것 같네요...

twinwings의 이미지

중간고사 기간은 지났습니다. 프로젝트 기간 쯤 되겠죠...

(벚꽃시기 = 중간고사 시기)

그래서 그런지, 요즘 과제 묻는 질문이 너무 많다는게 정말 느껴집니다.

익명 사용자의 이미지

저는 네이X 지식in 수학 및 C/C++ 프로그래밍 분야에서도 활동중인데 거기는 대놓고 학교/학원 과제가 일상적으로 질문으로 올라옵니다.

그 쪽은 질문자 편의를 이상하다 싶을 정도로 잘 봐주는 곳인지라, 심지어는 문제집을 폰카로 찍어서 통째로 올리기도 하더군요.

뭐, 그런 성의없는 질문에 답이 달릴 일은 대체로 거의 없습니다만, 스스로 공부할 수 있는 귀중한 기회를 왜 그리들 쉽게 내던지는지 안타까울 따름입니다.

chanik의 이미지

지식X 사이트 등에서 질문자에게 관대한 것은 포인트 시스템 때문인 것 같습니다.
답변하고 채택받으면 점수가 쌓이고 타이틀이 올라가는..
오래전 경험입니다만, 마치 온라인게임 캐릭터 수치 쌓는 것 같이 은근히 중독성이 있는 것 같더군요.

이곳은 그런 시스템 없이,

- 질문이 유발하는 호기심 충족이나
- 커뮤니티에서 얻어가기만 하는 미안함.. 이 승화된 책임감?
- 곤경에 처한 타인을 보고 그냥 지나치지 못하는 마음

등이 동기가 되어 소통이 이뤄지는 곳이라 느낍니다.
그래서 질문자의 문제점을 지적하는 경우도 종종 있는 것이겠고요.

저런 곳은 그런 동기로 움직이는 분들도 있겠지만
그냥 포인트를 쌓기 위한 재료로써 질문을 대하는 분들이 많지 않을까 싶습니다.
손쉬운 답변이 가능한 식상한 질문을 만나게 되면 번거로우면서도 반가워하게 된다고 할까요?

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.