New2C: Problems understanding STRUCT Please HELP!!!! 
Author Message
 New2C: Problems understanding STRUCT Please HELP!!!!

Hi, I've been working with C for about two weeks, and am having
problems with the whole "struct" concept.

My teacher has given me an assignment. I have to create a program that
will allow user's to add , delete, modify, and list items to a disk
file.

I've decided to create a Video inventory list of sorts. I begin to
code and keep getting confused with what I can and cannot do with
struct.  Here is what I get

#include <stdio.h>

struct VideoFile
{    char name[25];
     char number[7];
     char qty[3];

Quote:
};

main()
{    additem();      //teacher says to do this

  do  
     { printf("Enter another title?");

         /* checks to see if answer is
                    yes or no or blablabla */

       additem();
      }  while (answer == 'Y');

additem()
{    
     inptr=fopen("a:\sample.txt","w+b");

     printf("Enter Video Title.");      /* I know that I should
     gets(Video.name);                       be calling the struct
     printf("Enter number.");               here somewhere, but
     gets(Video.number);                    where and how?   */
     printf("Enter Qty. ");
     gets(Video.qty);

     fclose(inptr);

     return;

Quote:
}

My program is supposed to keep going from main to additem and back
until user says NO. Each time that I go tio additem, it opens, writes
to , and closes the SAMPLE file.   Teacher does not want any arrays to
be used.

THERE IT IS.  Can someone please help???!!!!!!!



Wed, 05 Aug 1998 03:00:00 GMT  
 New2C: Problems understanding STRUCT Please HELP!!!!

Quote:

>Hi, I've been working with C for about two weeks, and am having
>problems with the whole "struct" concept.

Sorry, is this an entry for the latest competition, or a genuine
question?

Quote:
>My teacher has given me an assignment. I have to create a program that
>will allow user's to add , delete, modify, and list items to a disk
>file.
>I've decided to create a Video inventory list of sorts. I begin to
>code and keep getting confused with what I can and cannot do with
>struct.  Here is what I get
>#include <stdio.h>
>struct VideoFile
>{    char name[25];
>     char number[7];
>     char qty[3];
>};
>main()

int main (void)  would be nice.

Quote:
>{    additem();      //teacher says to do this

                      ^^
Teacher says don't do this.

Quote:

>  do  
>     { printf("Enter another title?");

>         /* checks to see if answer is
>                    yes or no or blablabla */

>       additem();
>      }  while (answer == 'Y');

Where is answer defined?  Where is it amended?

Quote:
>additem()
>{    
>     inptr=fopen("a:\sample.txt","w+b");

I think you mean either "a:/sample.txt" or "a:\\sample.txt".

Quote:

>     printf("Enter Video Title.");      /* I know that I should
>     gets(Video.name);                       be calling the struct

gets() is a big no-no.  fgets() is safer.

Quote:
>     printf("Enter number.");               here somewhere, but
>     gets(Video.number);                    where and how?   */
>     printf("Enter Qty. ");
>     gets(Video.qty);
>     fclose(inptr);
>     return;
>}
>My program is supposed to keep going from main to additem and back
>until user says NO. Each time that I go tio additem, it opens, writes
>to , and closes the SAMPLE file.   Teacher does not want any arrays to
>be used.
>THERE IT IS.  Can someone please help???!!!!!!!

What is the objective?

John

--
John Winters.  Wallingford, Oxon, England.



Sun, 09 Aug 1998 03:00:00 GMT  
 New2C: Problems understanding STRUCT Please HELP!!!!


Quote:
> #include <stdio.h>

> struct VideoFile
> {    char name[25];
>      char number[7];
>      char qty[3];
> };

> additem()
> {    
>      inptr=fopen("a:\sample.txt","w+b");

>      printf("Enter Video Title.");      /* I know that I should
>      gets(Video.name);                       be calling the struct
>      printf("Enter number.");               here somewhere, but
>      gets(Video.number);                    where and how?   */
>      printf("Enter Qty. ");
>      gets(Video.qty);

Right, you are close but you haven't created any instance of "VideoFile"
yet ...

struct VideoFile Video; /* Put this line where it fits */

This is probably all you need to finish your assignment ...

Quote:

>      fclose(inptr);

That is, if you actually save the information before closing the file. It
would not be a bad idea to declare inptr as a FILE* (Thats what you want
it to be, isn't it?). Nor would it be a bad idea to check out fprintf()

Quote:
>      return;
> }

Sorry, for now I can't help you any more without taking all the fun away
from you.

// Jens M Andreasen



Sun, 09 Aug 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help on my C code, dont understand how to fix my compiler errors (PLEASE HELP)

2. Learning Linked Lists, Code Attached, My understanding of code attached, Please confirm understanding

3. struct problem, please help

4. about struct problem!Please help me!

5. about struct problem!Please help me!

6. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

7. Please help me understand this...

8. Please help, I don't understand

9. Please help : cannot understand error mesg.

10. Cannot generate typelibrary... please help understand

11. Understanding UINT Help Please

12. Please help!!!!Please help!!!!Please help!!!!

 

 
Powered by phpBB® Forum Software