Ready, steady… save!
You don’t need a chart to join in. Here are 2 ways to record your savings:
1. Cross it off
Pop a chart into your first post. Saved an amount? Cross it out! Read more »
£0.01 £0.02 £0.03
2. Write it down
Skip the chart and add updates to your first post. Read more »
“Another +£3 saved today. Go me!”
Use +£ before each new saving so it counts towards your total.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
C programming
shutton54321
Posts: 921 Forumite
in Techie Stuff
Can anyone help me with this problem i am currently doing a project in college for c programming but need help on one bit, how can i check if an id for example is unique consiting of a letter number number number which is using structures? and how do i read or write from a file?
0
Comments
-
This is C++ but I assume its legal C as well, you use fopen and fscanf to read a file... Not sure about the other stuff, but im pretty sure theres similar thing for writing... I'll have a look
Mat
EDIT: just tested it and it is correct in C as well...
Another EDIT: I'm assuming fprintf therefore writes to a fileAnd when you're in need of someone
My heart won't deny you
Cus so many seem so lonely
With noone left to cry too baby0 -
See the file i/o, structures and arrays sections of this C Programming Tutorial.
Note that the comparison operators (==, <=, etc.) don't work on structs. To compare structs, you have to compare individual fields, e.g.:
if (s1.x==s2.x && s1.y==s2.y) ...
It is not possible to write if (s1==s2).0 -
I haven't done C in about 15 years but do you have to specifically use structures, to me it sounds something that you should be useing regular expressions for
IvanI don't care about your first world problems; I have enough of my own!0 -
To compare structs, you have to compare individual fields,
Or you can be clever and use a union and bitfields. I forget the precise syntax offhand.
For the unique part I guess you'll have to keep a list of all the IDs you've read and compare against that when you read in a new one. With a letter and three digits there's only 26,000 possibilities so you could just allocate an array with 26,000 entries (ints, bools or even bits if you want to save space), clear it at the start and set the appropriate entry when you read that value.0 -
IvanOpinion wrote:to me it sounds something that you should be useing regular expressions for
I'd agree as its what regular expressions are for. You just need to make sure that whatever C library you are using has a regular expression package.0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 355.9K Banking & Borrowing
- 255K Reduce Debt & Boost Income
- 456.2K Spending & Discounts
- 248.4K Work, Benefits & Business
- 606.1K Mortgages, Homes & Bills
- 179K Life & Family
- 263.9K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.7K Read-Only Boards