Another programming problem

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

Another programming problem

Postby Kenshin17 » Sun Jun 03, 2007 4:06 pm

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.
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby Slater » Mon Jun 04, 2007 3:22 am

Hmm... are .csv files markup or encrypted?
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Kenshin17 » Mon Jun 04, 2007 8:11 am

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.
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby Warrior4Christ » Tue Jun 05, 2007 1:58 am

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.
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Kenshin17 » Tue Jun 05, 2007 12:45 pm

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...
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby Mithrandir » Fri Jun 08, 2007 6:08 am

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]
User avatar
Mithrandir
 
Posts: 11071
Joined: Fri Jun 27, 2003 12:00 pm
Location: You will be baked. And then there will be cake.

Postby sticksabuser » Fri Jun 08, 2007 8:47 am

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...
User avatar
sticksabuser
 
Posts: 49
Joined: Fri May 18, 2007 5:13 am
Location: Morgantown, WV

Postby Kaligraphic » Fri Jun 08, 2007 12:24 pm

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.
The cake used to be a lie like you, but then it took a portal to the deception core.
User avatar
Kaligraphic
 
Posts: 2002
Joined: Wed Jul 21, 2004 12:00 pm
Location: The catbox of DOOM!

Postby Kenshin17 » Fri Jun 08, 2007 1:41 pm

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.
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 207 guests