[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Can a "buffer" be returned by a function?

Posted on 2004-10-24
2
Medium Priority
?
284 Views
Last Modified: 2010-04-17
I am doing a client/server program where the server checks a linked list for results.
How do I get (or is it even possible) one of the functions in the linked list to return
a buffer space?  Like if I wanted the function to search the list and return something like:

setw(30)<<title<<setw(30)<< artist<<endl;

for an undetermined amount of lines (titles and artists)...

Currently my linked list specification function is:
void linkedList::Title(string musicArtist)
{
        //create pointer called current
       //start at beginning of list ... search until end of list
       //if the current finds a node where artist == musicArtist
       cout<<current->title<<endl;  //print out title
       //so there could be zero to several lines printed out to the screen
}

But the server needs to take what this function finds and return it to the client.  How do I get it into a buffer instead of printing out to the screen?

Thanks...  

I guess I need to change this from "void" to "char" or "string" ...
 
0
Comment
Question by:bjw5d6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 9

Expert Comment

by:jhshukla
ID: 12396629
using stringstream you can "print" the output to string instead of to screen and then return the string to the client.
http://www.cplusplus.com/ref/iostream/stringstream/
0
 
LVL 9

Accepted Solution

by:
jhshukla earned 2000 total points
ID: 12396663
example:
stringstream  ss;
string str;
ss << "this is a string" << flush;
str = ss.str();
return str;


if you like to or have to use c-style strings you can wrap it in a buffer struct and return the struct. client can then get it's c-style string from the buffer.

struct buffer{
  char str[BUF_SIZE];
};
struct buffer buf;
strncpy(buf.str, ss.str().c_str(), BUF_SIZE);
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question