Date: Jan 16, 2013 12:30 PM
Author: Kevin Ellis
Subject: Help using textscan or sscanf


My problem is very simple, but I cannot find an efficient way to accomplish it. Here is an excerpt of my array (which is one column of a dataset):


ans =


I am trying to create a new account number in the form of a string. I need to append '4412' to the the last 9 digits of the above account numbers. So for the results is:

'4412926665001' - Account Numbers have 9 digits so this is easy
'4412615017' - Only has 6 digits so take the whole account number
'4412976936151' - Has 10 digits so drop first and append to '4412'

So my problem is difficult in that I need to use sscanf to find the last 9 digits of the account number (even if it has less or more) and then use strcat to append '4412' to the beginning. A few poor attempts:


These obviously do not work and I can seem to find a metacharacter in the sscanf documentation for indicating a way to start at the end of the string count back 8 characters and return the result. Does it sscanf always have to read left to right? Any help would be much appreciated. Thanks.

Kevin Ellis