Need help with array's 
Author Message
 Need help with array's

hello I'm trying to put together a guest registry program, and all
that i have left to do is put in a message/mail system where people
can leave small(3line)messages to other people....well i'm trying to
use structures and arrays to do this (i not very familiar with linked
lists)....but for some reason it won't work for me...does any one have
any ideas....this is what i'm trying to do..

structure for mail
struct pmail
{
char a[30];
char b[30];
char c[30];
char d[30];
char e[30];

Quote:
}

now for  each mail box i want 10 of the pmail structures
struct mbox
{
        struct pmail bmail[11]; i want the #0 array left blank.

Quote:
};

now i declare an example of pmail and mbox;

struct pmail umail[1];
struct mbox ubox;
i use  printf & gets to gather the info and strore it in umail, then
strcpy each of the feilds into ubox.bmail[1](fields)...then save it to
file. then i  fp=fopen("mail.dat","r+b");
           fread(&ubox,sizeof(mbox),1,fp);
then i go through the process of gettting the data for
ubox.bmail[2].(feilds).......then fwrite(&ubox,sizeof(mbox),1,fp);
                                fclose(fp);

then i try to print out the arrays  and  ubox.bmail[1] will have
gibberish....and ubox.bmail[2] will have the data i stored there(well
to a certain extent)....any ideas....when i declare my instance of
mbox....should i give that array an element   eg....mbox ubox[1];

thanks in advance
using Turbo C++ 3.0                    



Mon, 21 Jun 1999 03:00:00 GMT  
 Need help with array's
Quote:

>hello I'm trying to put together a guest registry program, and all
>that i have left to do is put in a message/mail system where people
>can leave small(3line)messages to other people....well i'm trying to
>use structures and arrays to do this (i not very familiar with linked
>lists)....but for some reason it won't work for me...does any one have
>any ideas....this is what i'm trying to do..

>structure for mail
>struct pmail
>{
>char a[30];
>char b[30];
>char c[30];
>char d[30];
>char e[30];
>}
>now for  each mail box i want 10 of the pmail structures
>struct mbox
>{
>    struct pmail bmail[11]; i want the #0 array left blank.
>};

>now i declare an example of pmail and mbox;

>struct pmail umail[1];
>struct mbox ubox;
>i use  printf & gets to gather the info and strore it in umail, then
>strcpy each of the feilds into ubox.bmail[1](fields)...then save it to
>file. then i  fp=fopen("mail.dat","r+b");
>       fread(&ubox,sizeof(mbox),1,fp);
>then i go through the process of gettting the data for
>ubox.bmail[2].(feilds).......then fwrite(&ubox,sizeof(mbox),1,fp);
>                            fclose(fp);

>then i try to print out the arrays  and  ubox.bmail[1] will have
>gibberish....and ubox.bmail[2] will have the data i stored there(well
>to a certain extent)....any ideas....when i declare my instance of
>mbox....should i give that array an element   eg....mbox ubox[1];

>thanks in advance
>using Turbo C++ 3.0                



Tue, 22 Jun 1999 03:00:00 GMT  
 Need help with array's

hello I'm trying to put together a guest registry program, and all
that i have left to do is put in a message/mail system where people
can leave small(3line)messages to other people....well i'm trying to
use structures and arrays to do this (i not very familiar with linked
lists)....but for some reason it won't work for me...does any one have
any ideas....this is what i'm trying to do..

structure for mail
struct pmail
{
char a[30];
char b[30];
char c[30];
char d[30];
char e[30];

Quote:
}

now for  each mail box i want 10 of the pmail structures
struct mbox
{
        struct pmail bmail[11]; i want the #0 array left blank.

Quote:
};

now i declare an example of pmail and mbox;

struct pmail umail[1];
struct mbox ubox;
i use  printf & gets to gather the info and strore it in umail, then
strcpy each of the feilds into ubox.bmail[1](fields)...then save it to
file. then i  fp=fopen("mail.dat","r+b");
           fread(&ubox,sizeof(mbox),1,fp);
then i go through the process of gettting the data for
ubox.bmail[2].(feilds).......then fwrite(&ubox,sizeof(mbox),1,fp);
                                fclose(fp);

then i try to print out the arrays  and  ubox.bmail[1] will have
gibberish....and ubox.bmail[2] will have the data i stored there(well
to a certain extent)....any ideas....when i declare my instance of
mbox....should i give that array an element   eg....mbox ubox[1];

thanks in advance
using Turbo C++ 3.0                    



Tue, 22 Jun 1999 03:00:00 GMT  
 Need help with array's

Hello - I'm doing something at the moment very similar, so lets go over
this a little.

structure for mail
struct pmail
{
char a[30];
char b[30];
char c[30];
char d[30];
char e[30];

Quote:
}

now for  each mail box i want 10 of the pmail structures
struct mbox
{
        struct pmail bmail[11]; i want the #0 array left
blank.<<<------I assume this is not in your code.

Quote:
};

now i declare an example of pmail and mbox;

struct pmail umail[1];<<<---- I don't think you can reach into an
eddedded structure like this.  pmail is NOT an array, but a struct.

Try
struct pmail umail;
unmail.bmail[1] = "blah blah blah string.

Even better would be as follows:

struct pmail
{
char a[30];
char b[30];
char c[30];
char d[30];
char e[30];

Quote:
}mailbox[11];

struct mbox
{
       mailbox[11];

Quote:
} ubox;

Then access as follows
ubox.mailbox[1] = whatever;


Wed, 23 Jun 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help with array realloc's

2. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

3. array's of array's

4. need 'serialization' help in C

5. Need help unencrypting data with 'C'

6. Need Help Finding Sperry 'C' Compilers

7. 'incompatble types error'- help needed

8. Help Needed with 'Unhandled Exception' error

9. Need Help using DLL with 'C'

10. Need help understanding 'strtok'

11. Need help from MSVC guru's - GPF's with 16-bit

12. VB programmer needs help with C++ API's and DLL's

 

 
Powered by phpBB® Forum Software