Find the answer to your Linux question:
Results 1 to 2 of 2
hi, this is a code for string I/O in files: #include <stdio.h> main() { FILE *fp; char s[80]; fp=fopen("POEM.TXT","w"); if(fp==NULL) { puts("Cannot open file\n"); exit(0); } printf("Enter a few lines ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2004
    Posts
    46

    error coding for string I/O in files in C


    hi,
    this is a code for string I/O in files:
    #include <stdio.h>
    main()
    {
    FILE *fp;
    char s[80];

    fp=fopen("POEM.TXT","w");
    if(fp==NULL)
    {
    puts("Cannot open file\n");
    exit(0);
    }
    printf("Enter a few lines of text:\n");
    while(strlen(gets(s))>0)
    {
    fputs(s,fp);
    fputs("\n");
    }
    fclose(fp);
    }
    and this is the compilation error:
    [root@localhost i-o]# gcc -o l344 l344.c
    l344.c: In function `main':
    l344.c:17: error: too few arguments to function `fputs'
    plz point me where is the mistake and how to be written fputs("\n"),because this is not compiling.

  2. #2
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    You have numerous choices: puts("\n"), fputs("\n", stdout), putchar('\n') and so on.
    An on-line guide around C standard library would be a worthy position in your bookmarks list.
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •