Thread: matching the newline

  1. #16
    Registered User
    Join Date
    Jul 2005
    Location
    Transcarpathia
    Posts
    49
    I think this code might work (index overflow check must be added) :

    int ar[100], i, ch;
    for (i = 0; fscanf(fp, "%d%*[\t ]%1[\n]", &ar[i], &ch) == 1; i++)
    ;

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You should use code tags.

    Does fscanf() return 1, or merely a positive number?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    Registered User
    Join Date
    Jul 2005
    Location
    Transcarpathia
    Posts
    49
    Quote Originally Posted by dwks
    You should use code tags.

    Does fscanf() return 1, or merely a positive number?
    it returns the number of items scanned. the logic is inside the format
    string, and it is as follows:
    o scan a digit
    o pass spaces and tabs, if any
    o try to scan newline

    so if fscanf returns 0 or -1, nothig had beed scanned and loop should stop.
    if it returns 1, only digit had been scanned. fscanf() should eat all whitespaces up to the next digit.
    if it returns 2, digit and newline scanned, so loop should stop.

  4. #19
    Registered User
    Join Date
    Jul 2005
    Posts
    14
    Hi guys ,,

    Now , I have another problem , I tried but it doesn't work , suppose we have data file as before

    0 1 3 4
    1 3
    2 4

    I don't need print out the 2ed row because is already in the first , I mean (1 3) in the 2ed row is duplicated , how can i do this !!!

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Instead of printing them out, store what you have some place. (Linked List - See the FAQ / Prelude's corner, Google, board search, etc. Or an array, or...) Then run through what you have stored whenever you read something in and if it's already there, don't store it.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. Matching numbers
    By kirksson in forum C Programming
    Replies: 7
    Last Post: 07-23-2008, 01:51 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. Brace matching
    By coskun in forum C Programming
    Replies: 6
    Last Post: 07-30-2004, 06:45 AM
  5. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM