while(scanf("%[^'\n']s", srt) == 1); Can you tell me how to use scanf()?

This is a discussion on while(scanf("%[^'\n']s", srt) == 1); Can you tell me how to use scanf()? within the C Programming forums, part of the General Programming Boards category; Q1, Is [a-z], [^x], ... these simple regular expressions in the stardard of C? I mean, OK in most implements? ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    16

    while(scanf("%[^'\n']s", srt) == 1); Can you tell me how to use scanf()?

    Q1, Is [a-z], [^x], ... these simple regular expressions in the stardard of C? I mean, OK in most implements?

    scanf looks strange to me. What will scanf actually do in the while loop?
    Q2, How does it do to the final character before blank? What do I get from the stdin in the next time?

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    16
    Newbie have to go to bed.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Yes. The brackets makes scanf match the certain set of characters specified, and by prefixing the set with ^ you tell it to match everything except those characters.

    So this will match any string and exclude the terminating newline. You should never use scanf like that though since it could lead to buffer overflows.
    Code:
    scanf("%[^'\n']s", srt)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework help
    By mkdl750 in forum C Programming
    Replies: 45
    Last Post: 07-17-2008, 09:44 PM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. Need an extra pair of eyes ....
    By Whoputthatthere in forum C Programming
    Replies: 5
    Last Post: 06-02-2006, 12:19 PM
  4. process killer on a loop
    By Anddos in forum Windows Programming
    Replies: 8
    Last Post: 01-11-2006, 12:50 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21