Buffer Logic

C++ program help - using
This is the program:
#include
#include
using namespace std;
const char *get_greet();
int main(int argc, char **argv)
{
if(argc<2)
{
cout <<"please enter name" << endl;
}
cout << get_greet() << " " << argv[1] << "!" << endl;
return 0;
}
The questions are:
1. Write pseudo code illustrating the logic you will have in the function get_greet
2. If definition of get_greet was "void get_greet(char *buffer, int size)", what are the changes you have to do to main() to get it working?
Any help is appreciated.
Thank you so much
This is NOT homework. And it is not any sort of schoolwork/tutorial.
I have already tried it out, but I get an error. I checked documentation, but that was no help.
Looks to me like get_greet returns a greeting specific to the time of day, so if hours < 12 it would be "Good Morning" or if hours>18 "Good Evening." Why don't you open up your time.h header file or look up the documentation elsewhere (I use GCC. They kind of EXPECT you will open and read your header files if you want to use them properly).
The answer to number two seems obvious but if this is homework believe me, we are doing you no favor by answering that question.
EDIT: Okay, the point would be you would want to extract hours from an asctime() string. I've added a discussion of it in sources. The asctime() string is a fixed-length string, so you simply go to the place where hours start, extract that and the next char, convert them to an integer (probably using itoa() which means storing them in a 3-char string and making the third char ' ') and going from there.
The answer to your second question of course is in theory you can just do a cout << get_greet(buffer, SOME_SIZE) << " " << argv[1] << "!" << endl; assuming SOME_SIZE is #defined up above as the maximum number of chars to put in buffer and buffer is defined as a block of memory which is large enough to hold enough chars. {Incidently, I tend to send printf and cout ' ' and '!' rather than " " and "!" because when you use single quotes it sends chars but when you use double quotes it sends a two char array with the second char being' '. I know it doesn't save a lot but I've been questioned about why my code compiles smaller than some other peoples}.
You CAN do the above. It will evaluate get_greet(buffer, SOME_SIZE). It may be easier for you if you execute that above the cout statement and then just send it buffer.
Again, you either have to declare buffer as an array of fixed size, or allocate enough memory using malloc and remember to free it before exiting. And of course you can send get_greet a variable or a const or a digit, but the advantages of #defining a SOME_SIZE are if you have to use it elsewhere in the program you change it once -- while the program gets no chance to change it as the preprocessor will substitute whatever number is there for every occurance of SOME_SIZE, and with the right name people will know exactly what it is for.
Is that helpful?
No items matching your keywords were found.
![]() |
Glyph Technology 1TB Quad Desktop Hard Drive
List Price: |
DescriptionGlyph's GT 050Q builds upon the success of the original GT 050 and adds FireWire 800, eSATA and USB ports. With high-speed access to audio and video content, and flexible connectivity options, the GT 050Q's design features an internal Power Supply, whisper-quiet fan, and a 1/8" thick-brushed stainless steel faceplate... Features
|
![]() |
Seagate FreeAgent Go 500 GB USB 2.0 Portable External Hard Drive ST905003FGA2E1-RK (Silver) |
DescriptionEasily take your photos, music, videos and documents everywhere with the sleek Seagate FreeAgent Go portable storage solution.The FreeAgent Go drive offers up to 500GB of capacity, so you can comfortably store all your files... Features
|
![]() |
8-PORT Int., 6GB/S Sata+sas, Pcie 2.0, 1GB Ddriii; In The Box: Mr Sas 9265-8I, Q
List Price: |
DescriptionLSI Logic MegaRAID 9265-8i SAS RAID Controller - Serial Attached SCSI, Serial ATA/600 - PCI Express 2.0 x8 - Plug-in Card LSI00277 Hard Drive & RAID Controllers Features
|
![]() |
Targus Citygear York Black Grey Yellow Nylon Notebook Case
List Price: |
DescriptionAlso included are a removable mesh accessory pouch, removable CD/DVD sleeves that hold 8 discs and a detachable mobile phone case. There is a rear document storage section and a luggage strap for easy attachment to rolling cases. Features
|
![]() |
New Targus Black Blue Neoprene Notebook Slip Case Top Loading Shoulder Strap Handle Compact
List Price: |
DescriptionIt has ample space in the front and interior storage sections for business cards, pens, keys and files. Also featured is the unique shock-absorbing EqualizerStrap that evenly distributes weight over your shoulder for greater comfort. Features
|
![]() |
Targus Citygear Miami Black Yellow Nylon Messenger Case For 17 Inch Notebook
List Price: |
DescriptionThere is a padded notebook compartment, a section for file storage, removable mobile phone pocket and even a hidden water bottle pocket. Sleek and professional, this case supports notebooks with up to 17 inches screens. Features
|
![]() |
HEX LOGIC DA/ PORTER CABLE BUFFING PAD SAMPLER PLATTER -HEX-LOGIC PADS + DA BACKING PLATE |
DescriptionHex-logic pads are engineered and developed for today's pickiest detailing professionals. Engineered, developed and tested to specific requirements of our OEM clients these pads utilize the best foams from around the world and the latest of testing and research and development including Chemical Guys own Self Centered backing system! The Hex-Logic Chemical Guys Pads are meant to work on flat or rounded/angled surfaces... Features
|
![]() |
HEX LOGIC 6.5" BEST OF THE BEST BUFFING PAD EVERYTHING KIT + FREE BONUS (8 ITEMS) |
DescriptionHEX-LOGIC -Yellow Heavy Cutting Pad 6.5" (yellowed) Features
|










Toshiba 46
Samsung Lcd
LG 3D Tv
Toshiba 52 Inch
Sony Watchman
Sony Xbr6
Non Functional
Oem Dlp
Zenith Dlp