Thread: Implement function into this program?

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    22

    Implement function into this program?

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    struct Books {
       char  Name[50];
       char  author[50];
       char  subject[100];
       int   book_id;
    };
    
    
    int main( ) {
    
    
       struct Books Book1;        /* Declare Book1 of type Book */
       struct Books Book2;        /* Declare Book2 of type Book */
    
    
       /* book 1 specification */
       strcpy( Book1.Name, "C Programming Learning ");
       strcpy( Book1.author, "Nuha Ali");
       strcpy( Book1.subject, "C Program");
       Book1.book_id = 6495407;
    
    
       /* book 2 specification */
       strcpy( Book2.Name, "Telecom  Learning");
       strcpy( Book2.author, "Zara Ali");
       strcpy( Book2.subject, "Telecom");
       Book2.book_id = 6495700;
    
    
       /* print Book1 info */
       printf( "Book 1 Name : %s\n", Book1.Name);
       printf( "Book 1 author : %s\n", Book1.author);
       printf( "Book 1 subject : %s\n", Book1.subject);
       printf( "Book 1 book_id : %d\n", Book1.book_id);
    
    
       /* print Book2 info */
       printf( "Book 2 Name : %s\n", Book2.Name);
       printf( "Book 2 author : %s\n", Book2.author);
       printf( "Book 2 subject : %s\n", Book2.subject);
       printf( "Book 2 book_id : %d\n", Book2.book_id);
    
    
       return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I might define two functions:
    • A function to populate a struct Books object given a pointer to the object and its member values.
    • A function to print a struct Books object.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    33
    Yes, what she said.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to implement a function
    By BMWE in forum C Programming
    Replies: 8
    Last Post: 03-25-2012, 02:25 PM
  2. Replies: 3
    Last Post: 11-15-2011, 10:49 PM
  3. Replies: 9
    Last Post: 11-12-2007, 03:29 PM
  4. How do I implement a Tempo function in my sequencer?
    By electrolove in forum C Programming
    Replies: 7
    Last Post: 02-17-2003, 04:29 AM
  5. implement hash program
    By Abdi in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 11:22 PM

Tags for this Thread