Structures
Hey all :)
I've been trying to get into structures for a while but can't figure out how to use them to their full potential. What i'm trying to do is have a file with 3 fields: name, password and comment. I wanna be able to use a structure to view/add these fields. How easy is this to do? I understand how to get info (i.e. i've been working with the passwd structure alot) but not how to lay everything out.... Oh BTW i'm programming in C :) Thanks in advance :D |
It's quite easy!
usign fread/read or fwrite/write you can read a record or store a record in a file. Code:
structure user{ |
K wow :) I've never run into fwrite so didn't that either (guess it takes longer to learn all the functions you can you than I thought :D
Ummm had to change a few things (some syntax errors) but the fwrite requires 4 arguments, not 3... I had a read of the man page for it and it's meant to be something like this: Code:
fwrite (u, 255, 3, fp); Also as we gave this structure an alias of u do we call the information like this: Code:
struct user *foo; Thanks heaps - u've already shown me quite a bit :D :study: |
Also is it possible to dynamically make structures from variables - i.e.
Code:
char name[256]; :newbie: |
Nopes you can not dynamicly create structures.
But you could create "name-value" pairs. Code:
struct pair { Code:
struct pair files[2]; |
erh.. files[2] should be fields[2] =)
|
Kewl i'll read up a bit more on the pair type and see how I go... Thanks :D
Also just bought "C by Example" and looks like a really good book, might learn a few things from it :) Thanks all |
All times are GMT -5. The time now is 02:37 AM. |