Page 1 of 1

Another programming problem

PostPosted: Sun Jun 03, 2007 4:06 pm
by Kenshin17
Ok so here is what I want to do.

I have a hand scanner, ie a portable device that scans barcodes and proccesses data. I want to program it store data on what it scans and then as I scan to search what it has already scanned. If what I am scanning has been scanned before I want it to increase the quantity in that item and not simply add a new record.

The problem is this, the device runs on C and I am not very familiar with C. I need to write a simple program that will search the data file (which it creates as a .txt file) and determine if it has been scanned before. If it has then it needs to incriment the quanity field by one, if not then it needs to add the newly scanned item to the data file.

Info that might be useful, the scanner basically creates a .csv file, even though it puts the .txt extension on it. I need to search that file.

Any help would be great and if you need anything more let me know.

PostPosted: Mon Jun 04, 2007 3:22 am
by Slater
Hmm... are .csv files markup or encrypted?

PostPosted: Mon Jun 04, 2007 8:11 am
by Kenshin17
It stands for Comma Separated Values
Its an abhorrently simple file format, like so:

Field,Field, Field
Field, Field, Field

It simply means that the individual data is seperated by a comma in the file.

PostPosted: Tue Jun 05, 2007 1:58 am
by Warrior4Christ
Is the program to run on the scanning device itself? Or does the program run on the computer, and the scanner connect to that?

Assuming you have enough memory to fit the whole list in memory at once (as many items as you expect to have), then I would definitely have it load the whole list on start up into a data structure in memory, and write it to the file when it closes.

If I were doing this in a high level language, I would chose a Map data structure, which is a key-value data pair. The key is unique, and ideally easy to find in a list (ie. sorted), and the value in your case would the count of instances of that bar code. To make it nice and fast, I'd chose something like a TreeMap or HashMap in Java (http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html - the documentation, if that happens to be of any use).

Of course, you'd have to implement this in C, which is not object oriented... but it is doable.

PostPosted: Tue Jun 05, 2007 12:45 pm
by Kenshin17
Hm...i was more or less trying to see if I could do this...its not something I need, but it looks like it might be beyond my ability in C, way beyond XD Now if this was VB...

PostPosted: Fri Jun 08, 2007 6:08 am
by Mithrandir
You might also consider using a split-regular expression format, if the language you decide to parse the file with supports it. You'll end up with a regex like:

[php]
$myarray = split('/\s*,\s*/', $the_data);

[/php]

PostPosted: Fri Jun 08, 2007 8:47 am
by sticksabuser
Well, actually the C program needed for this shouldn't be too complex... It can be but you can simplify it.

Can you post a sample of the CSV file?

PS: you probably won't need anything beyond string manipulation, file I/O, and arrays...

PostPosted: Fri Jun 08, 2007 12:24 pm
by Kaligraphic
If you have it scan through the entire file, then scanning large numbers of barcodes could slow down the machine. The extent, of course, would depend on the speed of the storage and processor, but it might be easier to do something like block off a good bit of memory for an array of structs. Then again, if you have low memory, going with the file might be better.

It kind of depends on what the limiting factors are.

PostPosted: Fri Jun 08, 2007 1:41 pm
by Kenshin17
0_0

Ok....I am a bit lost....I think I bit off more then I could chew....

I don't feel I can post a section of the CSV, its work related. Also its not necessarily a straight up C program. I mean the scanner uses C but I write the programs using a special program that lets me make a graphical flowchart of the program. It then converts the flowchart, and permiters I specify, into C and downloads them. I can put a node on the flowchart that lets me write C programs, but I am not sure how well any ol' generic C program will do.