Seperating whitespaces and Floating poing numbers and Strings.

I've made a program that creates and builds a variety of spreadsheets with customizable dimensions etc..... for things like.
Price lists and recommended retail prices.

Anyways i had no trouble creating that program but now i'm stuck with a simple problem thats annoying me!

So the program has the option to view the spreadsheet, search for items in the spreadsheet. and edit it and add items to it.
But to do any of that i need to know how to process the text files the spreadsheets are saved in.

They can be build with lines.


|Items |Price |Qty |Total |
|---------|-------|------|-------|
|Mum |2.22 |4 |8.88 |
|Dad |2.22 |4 |8.88 |
|----------|-------|------|-------|
Grand Total |17.76|


Or without lines


Items Price Qty Total
-----------------------------
Pencil 0.55 10 5.5
Pen 1.23 10 12.3
-----------------------------
17.8


Um they line up perfectly in consoles font.
Edit:Wait it''s not the font i think the site is resizing it.


Anyway the numbers in them are separated by whitespaces and this strange symbol i don't know the name of "|" That one.

So how would i go about separating all the floating point numbers and strings?
I've already Processed each line to a string which is in a array.




Last edited on
Bump
'|' is called a pipe. If you want to post with equal-spaced font, use the code tags, by clicking on the # under format.

What you could easily do is go through and replace all the pipes with spaces. Then you could just fscanf() the thing looking for valid numbers, or what-not, because that function pretty much ignores whitespace.
Last edited on
Thanks man!
I'll give that a go.
Could someone help me use fscanf i'm lost with the tut on this site.
actually scanf all together i don't understand it.
Last edited on
fscanf() isn't going to make too much sense at first if you have never used fprintf() or printf().

The second argument you pass to fscanf() is a formatting string. This tells it what to expect. Say the first thing you want it to do is read a string, but you don't want the first character from the file to be in that string, you would give it %c, for char, in quotes, then %s for string. For everything you tell it to read, you must pass a corresponding variable in order.

1
2
3
FILE *handle = fopen("My Test File.txt");
char c0,str[100];
fscanf(handle, "%c%s", &c0,str);


Also, you need to pass the address (note the & ); because C is pass-by-value, the function couldn't change your stuff unless it had the values of the addresses. Hopefully this gets you through the day, or somebody else uses this more often than cin and can help -- I gotta go to work :P
Topic archived. No new replies allowed.