Library Creation

This is a discussion on Library Creation within the C++ Programming forums, part of the General Programming Boards category; Code: #include <string.h> #include <conio.h> #include <iostream.h> void center(char txt[60], int height) { int number, spaces; number = strlen(txt); spaces ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    72

    Library Creation

    Code:
    #include <string.h>
    #include <conio.h>
    #include <iostream.h>
    
    
    void center(char txt[60], int height)
    {
    
    
    	int number, spaces;
    
    	number = strlen(txt);
    	spaces = 40 - number/2;
    
    	gotoxy (spaces,height);
    	cout << txt << endl;
    
    }
    how would i put this into a library so i could use this for any program.

  2. #2
    btq
    btq is offline
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    you want it static or dynamic?

    /btq
    ...viewlexx - julie lexx

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    72
    im not sure what that means. What ever works best and is simplest.

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >What ever works best and is simplest.

    It depends what you want to do with it?

    Do want other people with different compilers to use your library? Or is just for yourself?

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Originally posted by niroopan
    im not sure what that means. What ever works best and is simplest.
    Static means never changing

    Dynamic means it changes.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    72
    i would like it to be never changing

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    72
    i just want it for myself

  8. #8
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Code:
    #include <windows.h>
    #include <string>
    
    #ifndef _CENTRE_H
    #define _CENTRE_H
    
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    void center(char txt[60], int height)
    {
    	int number, spaces;
    
    	number = std::strlen(txt);
    	spaces = 40 - number/2;
    
    	gotoxy (spaces,height);
    	cout << txt << endl;
    }
    
    #endif
    Stick that in a header file, call it "centre.h" or "center.h" if you're a yank. Then, place it in the directory of the program you're attemping to compile and #include "centre.h"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PDF creation library in C
    By saadahmed42 in forum C Programming
    Replies: 1
    Last Post: 07-10-2008, 09:48 AM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  4. Shared Library creation tips
    By ezwise in forum C Programming
    Replies: 6
    Last Post: 03-01-2005, 02:29 PM
  5. graphic library creation
    By bob5845 in forum C++ Programming
    Replies: 1
    Last Post: 04-04-2002, 11:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21