Thread: stop read in newline

  1. #1
    Registered User
    Join Date
    Sep 2001

    stop read in newline

    hi all, i'm so mess up w/ this pro.
    suppose a data file File.dat:

    a b c d e
    f g

    how can i stop read those character when matching the newline?
    note: # of words must be counted

    my code:
    int main()
         char word;
         FILE *in;
         int i=0;
         while(fscanf(in, "%c", &word)!=EOF)
              printf("%c\n", word);
                printf("newline matched, stop reading file!\n");
          printf("%d words are read, bye\n", i);
        return 0;
    thanx for any help!!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    %c is a single character, not a string.
    %s is a string.

    fgets() will read a string, including, but not past, the newline.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 09:18 AM
  2. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  3. Binary files read newline (help)
    By Perimeter in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2003, 08:08 AM
  4. fgets and a bothersome newline char
    By ivandn in forum Linux Programming
    Replies: 1
    Last Post: 11-14-2001, 01:41 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM