-7

I have a couple of questions.
I need to write a program(winapi) that will create a buffer of a fixed size, then append strings to it and returns it.
1. Is it even possible for "main" to return a buffer? 2. How should I create, append string and return it?

I am not new to C, but I have very little experience with buffers and strings handling.
Thank you!

  • 1
    Yes, `main` can/may return _integer_ but not _buffer_, but first of all try something to write by yourself. Read [this](http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c). – rakeb.mazharul Jul 02 '15 at 07:48
  • 1
    Welcome to Stack Overflow! Please take the [tour](http://stackoverflow.com/tour) and read [How to Ask](http://stackoverflow.com/help/how-to-ask) to learn what we expect from questions here. Please be aware that we do not provide _from-scratch_ coding service. Please show us what you've tried already, how it failed and we might be able to help.:-) – Sourav Ghosh Jul 02 '15 at 07:49
  • 1
    Too add on to what @SouravGhosh said, this is not a place where we don't put in effort and demand answers. Put in some effort, and we will put in effort to help – Universal Electricity Jul 02 '15 at 07:51
  • @SouravGhosh, I was looking for some good link for OP about what `main` returns, then I will inform you about the update. Cheers! – rakeb.mazharul Jul 02 '15 at 07:57
  • It sounds like you either have misunderstood the problem description or the problem description is unclear. (It's common for beginners to confuse *return* and *output*, so that might be the issue.) – molbdnilo Jul 02 '15 at 08:02

2 Answers2

0
  1. Is it even possible for "main" to return a buffer?

No and you shouldn't. What should main() return in C and C++?

  1. How should I create, append string and return it?
char aString[FIXED_SIZE];
memset(aString, 0, sizeof aString);
strcpy(aString, "This is a string");
Community
  • 1
  • 1
moffeltje
  • 4,095
  • 4
  • 24
  • 49
0

main in c only returns an integer, which is used to indicate the success or failure of the program.

See What should main() return in C and C++?

What you might want to consider is writing to stdout (What does it mean to write to stdout in C?) or direct to a file.

Community
  • 1
  • 1