473,394 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

string count help --> C++

hey im new, howdy. here is my prob, i am have this problem using the string count function, i am trying to center some text. looking at my code will clarify. i will be forever in debt to whoever helps. thanks
Expand|Select|Wrap|Line Numbers
  1. //Linemaker.h
  2. #ifndef _LM_H
  3. #define _LM_H
  4.  
  5. class LineMaker
  6.  
  7. {
  8. private:
  9.  
  10.     int limitlength;
  11.  
  12. public:
  13.  
  14.     LineMaker();
  15.  
  16.  
  17.     void MakeLine(char line[]="-", int length=79, unsigned char type=215,
  18.          unsigned char left=25, unsigned char right=25);
  19.  
  20.     void Center(char text[], char result[], int width=79, unsigned char fill=' ',
  21.          unsigned char left=25, unsigned char right=25);
  22.  
  23.  
  24.  
  25.  
  26.  
  27. };
  28.  
  29. #endif
  30.  
Expand|Select|Wrap|Line Numbers
  1. //Linemaker.cpp
  2. #include <iostream>
  3. #include "Linemaker.h"
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. LineMaker::LineMaker()
  9. {
  10.  
  11.     limitlength=79;
  12.  
  13. }
  14.  
  15. void LineMaker::MakeLine(char line[], int length,
  16.                          unsigned char type, unsigned char left, unsigned char right)
  17. {
  18.  
  19.     int i;
  20.  
  21.     cout << left;
  22.  
  23.     for (i=0; i<length; i++)
  24.     {
  25.         cout << line;
  26.     }
  27.  
  28.     cout << right;
  29.  
  30.  
  31.  
  32. }
  33.  
  34. void LineMaker::Center(char text[], char out[], int width, 
  35.                        unsigned char fill, unsigned char left, unsigned char right)
  36. {
  37.  
  38.     int i;
  39.  
  40.     cout << left;
  41.  
  42.     for (i=0; i<width; i++)
  43.     {
  44.         cout << fill;
  45.     }
  46. int count(char text[]);
  47.     cout << text;
  48.     cout << right;
  49.     cout<<endl;
  50.  
  51. }
  52.  
Expand|Select|Wrap|Line Numbers
  1. //Linemaker.cpp
  2. #include <iostream>
  3. #include "Linemaker.h"
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. LineMaker::LineMaker()
  9. {
  10.  
  11.     limitlength=79;
  12.  
  13. }
  14.  
  15. void LineMaker::MakeLine(char line[], int length,
  16.                          unsigned char type, unsigned char left, unsigned char right)
  17. {
  18.  
  19.     int i;
  20.  
  21.     cout << left;
  22.  
  23.     for (i=0; i<length; i++)
  24.     {
  25.         cout << line;
  26.     }
  27.  
  28.     cout << right;
  29.  
  30.  
  31.  
  32. }
  33.  
  34. void LineMaker::Center(char text[], char out[], int width, 
  35.                        unsigned char fill, unsigned char left, unsigned char right)
  36. {
  37.  
  38.     int i;
  39.  
  40.     cout << left;
  41.  
  42.     for (i=0; i<width; i++)
  43.     {
  44.         cout << fill;
  45.     }
  46. int count(char text[]);
  47.     cout << text;
  48.     cout << right;
  49.     cout<<endl;
  50.  
  51. }
  52.  
Jun 11 '06 #1
1 5376
Banfa
9,065 Expert Mod 8TB
Unfortunately you haven't stated what this code is meant to do or what it actually does. The actual problem.

This makes it hard to solve the problem.

However if you are trying to centre text on a console window then what you need to do is output

(width of screen - width of text) / 2 spaces before the text.
Jun 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ntg85 | last post by:
Can you use variables in string.count or string.find? I tried, and IDLE gives me errors. Here's the code: while list: print letter = raw_input("What letter? ") string.lower(letter) guess =...
0
by: - | last post by:
i have a query as follows and is unsure whether it is mysql or php: $result = mysqli_query("SELECT COUNT(*) > @foobar AS status ....") where it's suppose to get a one row value of either '0' or...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
7
by: Matteo Rattotti | last post by:
Hi all, i've noticed a strange beaviour of string.count: in my mind this code must work in this way: str = "a_a_a_a_" howmuch = str.count("_a_") print howmuch -> 3
2
by: ericv | last post by:
I have 3500 records in a table - each record has a unique value (KEY_ID field), but some records share the same value (in a field called POLE_ID) So, there may be 3 records that have the POLE_ID...
1
by: michael.martinek | last post by:
Greetings! I've recently been trying to do something, which apparently looks like it may be a little odd.. I'm not finding anything in the manuals or anywhere on the web where something similiar...
60
by: sang | last post by:
Hello i have a doubt in string count with the sub string. the main string is "java,mysql,jsp,java,html"; the sub string is like this "java,mysql" The output is like this java 2...
4
by: thayes5150 | last post by:
I have an Access 2003 database linked to an MS SQL 2005 backend. We use the database as part of a process whereby we use Zone OCR to scan records off paper forms into an XML file, suck the data off...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.