Thread: Reading Multiple strings in C programming

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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.

  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, 02: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