Thread: sscanf help!!

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    sscanf help!!

    I'm trying to read in this list of data entries and then find particular parts of the entry out. I have been told that sscanf is what to use but am having absolutely no luck! I think part of the problem is I don't know the proper format for sscanf... here's the code I currently have... any help would be much appreciated

    Code:
    for (j=0; j< max_number; j++)
    			{
    			   for (t = 0; t<max_number && sscanf (list_of_runners, "%c", &gender) == '('; t++)
    				{
    				age_index = t;
    				age_array [age_index]++;
    
    				}
    			}
    I also don't know if age_array[age_index] will increment the number stored in the spot age_index of the array!

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    sscanf returns "the number of input items assigned".
    Code:
    sscanf (list_of_runners, "%c", &gender) == '('
    In this case it should return 1 when it is successful. You might be on some strange non-ASCII system for which ')' is equal to one, otherwise this will always evaluate to false, which in turn makes the whole loop control condition evaluate to false.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    Thanks I've tried using that... and maybe it's just that I'm tired... or maybe just that I am dumb (going for the former not the latter!) but I just can't get my program to scan up to the "(" and then store the the number enclosed in the parenthesis!
    When I ask it to only print if sscanf == 1 I get nothing and if I ask it to print if sscanf !=1 I get an infinite loop

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    1 1 1 Abdelkhader El Mouaziz (31) NIKE, MAR 2:10:09 2:10:09 30:26 1:03:08 1:36:51 4:58

    The stuff in bold is what I want to extract

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    Thanks so much! It finally works!!! Yay!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sscanf and string handling question
    By ursula in forum C Programming
    Replies: 14
    Last Post: 05-30-2009, 02:21 AM
  2. Problem using sscanf fgets and overflow checking
    By jou00jou in forum C Programming
    Replies: 5
    Last Post: 02-18-2008, 06:42 AM
  3. Problems reading formatted input with sscanf
    By Nazgulled in forum C Programming
    Replies: 17
    Last Post: 05-10-2006, 12:46 AM
  4. sscanf question
    By Zarkhalar in forum C++ Programming
    Replies: 6
    Last Post: 08-03-2004, 07:52 PM
  5. sscanf (I think)
    By RyeDunn in forum C Programming
    Replies: 7
    Last Post: 07-31-2002, 08:46 AM