Reading Multiple strings in C programming

This is a discussion on Reading Multiple strings in C programming within the C Programming forums, part of the General Programming Boards category; I want to read characters until third period encounters that is reading three strings. I am using the following code ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    2

    Post Reading Multiple strings in C programming

    I want to read characters until third period encounters that is reading three strings.

    I am using the following code

    Code:
    scanf("%s%,s,%s",str1,str2,str3);
    But it is reading only one string

    please tell me how to read three strings

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    > scanf("%s%,s,%s",str1,str2,str3);
    See it yet?

    Besides, %s will also read commas, so all you'll end up with is one string "abc,def,ghi" in str1

    If you want to do (simple) comma separated values, then use this
    scanf("%[^,],%[^,],%[^,]",str1,str2,str3);

    See your manual page for more details on the %[ format.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    2
    Sorry while posting I did mistake
    Its not

    Code:
    scanf("%s%,s,%s",str1,str2,str3);
    Actually i am using

    Code:
    scanf("%s,%s,%s",str1,str2,str3);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple char strings into one string
    By tlkuvic in forum C Programming
    Replies: 1
    Last Post: 11-30-2010, 01:24 PM
  2. reading multiple strings from single row....
    By satty in forum C Programming
    Replies: 13
    Last Post: 08-06-2010, 07:39 AM
  3. Reading Multiple Multi-Part Strings From a Text File
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2009, 10:43 AM
  4. multiple nak strings
    By bhorrobi in forum C++ Programming
    Replies: 2
    Last Post: 08-09-2004, 12:44 PM
  5. Multiple Strings
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 08-15-2002, 11:41 AM

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