Hi,
I currently have a program that is able to write a string of characters(serial number) into a txt file.
The program will then read from the file and create another text file for printing.
I am trying to edit my program for tracking purpose, so there will be no chances of double printing. The ideal way will be creating a database and searching for it. However, it is too complex for me.
I am thinking of just using and searching through the text file for duplicates. ie once a serial number has been saved into a text file, any duplicate found will be detected and the program will prompt.
I need some help/example for searching through the text file for the serial number and prompt if it is duplicate.
Some part of my program is as follows. It is quite a lengthy code and it should be shorter but I am a C++ beginner.
Well you say beginner but there are lots of functions and commands in here that i don't understand!
However thinking of the database thing I suppose you could create the serial code one on each line, then on application launch it reads the file where they are stored and set pointer to ((ios::end)-SerialSize).
Here SerialSize is the size of the code you're storing (i assume they are all same length) and so this will set the pointer to the start of the last line...
Then you can simply read that bottem line to get your starting point and +1 for the next code (or whatever you do to increment code)
I see goto's in your code: -this is usually a bad idea, because it leads to spaghetti code.
Some good advice given by experienced programmers is (vlad from moscow is one)to: "Forget that the language has the capability of goto's"
Code can be written using loops (for, while or do). Also use functions to modularise the code.
There are STL algorithms that can search for strings. Basically use getline to read a line from file into a string. Use find algorithm to search for your string in this line-string.
Hi, the codes i used were copied and modified from examples found in the net. It took me a while to understand. By right, I should masked the serial numbers but I just can't find it, so I did a copy of the serial number and remove the memory one by one for my comparison.
The database numbers are appended. I see them are stored line by line automatically.
My serial numbers are of same length, 9 characters (12A456789). So is the size 9?
I ask because memmove, fclose, fprintf, strncmp, fgetc and fputc are C library methods.
You are free to mix and match at your pleasure but you might want to understand the differences between C and C++ as you go along so you don't get their libraries mixed up.
EDIT - This is actually a C program that uses cout statements.
That's why Satsumi was confused. lol
Erhmm, It's Satsuma :D
And yes i had a suspision that this was fairly backdated code (although C++ is designed to work with it's original C libaries) however i am a learner to C++ (getting to a fair standing with language now) so i don't know much about the original language and for now i'm not that curious 'cos i dont want to get muddled up.