Giter Club home page Giter Club logo

Comments (3)

bztsrc avatar bztsrc commented on July 27, 2024

You need a sufficiently big enough buffer. Depends on what you want to write.
If you also have a vnsprintf implementation, you can use the trick mentioned in the sprintf man page under the section EXAMPLE:

// To allocate a sufficiently large string and print into it (code correct for both glibc 2.0
// and glibc 2.1):

       #include <stdio.h>
       #include <stdlib.h>
       #include <stdarg.h>

       char *
       make_message(const char *fmt, ...)
       {
           int size = 0;
           char *p = NULL;
           va_list ap;

           /* Determine required size */

           va_start(ap, fmt);
           size = vsnprintf(p, size, fmt, ap);
           va_end(ap);

           if (size < 0)
               return NULL;

           size++;             /* For '\0' */
           p = malloc(size);
           if (p == NULL)
               return NULL;

           va_start(ap, fmt);
           size = vsnprintf(p, size, fmt, ap);
           va_end(ap);

           if (size < 0) {
               free(p);
               return NULL;
           }

           return p;
       }

Another possibility to implement printf in a way to output each and every character right on the spot, therefore no memory allocation needed at all. I've used sprintf to show you how it's done, and it was obvious to reuse that code for printf. But that's not the only way.

from raspi3-tutorial.

LizardLad avatar LizardLad commented on July 27, 2024

Just as a side note would you mind having a look at my post on the pi forums about audio please?

from raspi3-tutorial.

LizardLad avatar LizardLad commented on July 27, 2024

I finished a way to malloc memory for printf it is in my github repo if you wanted to look at it. I was unable to find how circle does audio so would you please check out this post: https://www.raspberrypi.org/forums/viewtopic.php?f=72&t=212930&sid=aeafdbf5f08d4d0563e61392c6cac157

from raspi3-tutorial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.