473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to parse string with sscanf that have a empty field?

Hi,

I am handling tab delimited txt files that have multiple fields. But some of the fields can be empty. So it will appear as <TAB><TAB> in the file rather than <TAB>something<TAB>. If I read in the line and then use something like


Expand|Select|Wrap|Line Numbers
  1. sscanf(buf0, "%s %ld %ld %s %s %s %s %s", chr, &bg, &ed, zg, var, ref, s1, s2);
  2.  
The program will skip these empty field and assign the value of the next non-empty field to the variable. What I really want it to do is to assign an empty string (length of 0) to the variable.

How can I write the sscan file to do the scanning? Of course, I can read the line character by character and check if anything is a <TAB> and turned the substring into a field value but that is a little awkard to my opinion. Any good and simple way to do this?

Thanks!

Shan
Jan 28 '11 #1
1 6234
horace1
1,510 Expert 1GB
if the format of individual lines varies I don't think you have any choice but to read each element individually and work out what it is, i.e. a <TAB> or a string.

You ould read the whole line in as a string then have a function which looks at the next element and returns "" if it is a TAB else the string, e.g.
Expand|Select|Wrap|Line Numbers
  1.     char* nextelement(char *inputstring, char *result)
  2.  
it would return a pointer to the start of the next elelemnt to read - used when you call the function next time.
Jan 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Daniel Lidström | last post by:
Hi, I'm currently using this method to extract doubles from a string: System::String* sp = S" "; System::String* tokens = s->Trim()->Split(sp->ToCharArray()); m_Northing =...
4
by: Marcel Brekelmans | last post by:
Hello, I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example: I have a simple table 'tblName': ID Name 1 Jane 2 Joe 2 Doe
13
by: temp | last post by:
Hi all, I know this is easy for you guys but I am not a VB developer. My boss just wanted me to generate a mapping of all the queries in our Access DB. So I managed to create some subroutines to...
2
by: David | last post by:
Hi, This is probably really simple but kinda has me stumped. I have taken over a data base and am looking to modify it to make it more user friendly. Currently, I have a Combo box with 4...
5
by: VMI | last post by:
How can I validate a null string or an empty string in the same IF statement? If I use this: if (myString.Trim().Length <= 0 || myString == null) { //do stuff } I'll get a run-time error...
1
by: Oleg Ogurok | last post by:
Hi all, I want to use RegularExpressionValidator to enforce non-empty integer format in a TextBox. However, the validator doesn't give the error when the textbox is empty. For example, if...
3
by: Joachim | last post by:
Hi I am a beginner in VB.NET, and have a problem with empty field in Access I have transfered a worksheet in Excel to Access table. Some of the cels are empty I use VB.NET program to acces...
5
ronverdonk
by: ronverdonk | last post by:
Does Access have a FIELD() function or something alike. I want to sort my query result in a non-standard order by specifying e.g. SELECT * from table_name ORDER BY FIELD(col_name, 'You', 'Me', 'We',...
3
by: Sheldon | last post by:
If I have the following string in a text field of a table: "This is a test" can I create an update query that will change, say, the string "is" to "xyz" in the two locations where it occurs or...
2
by: babansky | last post by:
How can i check if the string variable is empty? so that i the error undefined offset will not going to appear anymore? im doing a program that will output all of his children, then i cant do the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.