Thread: How do you embed data into a literal string ?

  1. #1
    Registered User
    Join Date
    Dec 2010

    How do you embed data into a literal string ?

    I am writing a program for a PIC microcontroller, which I have completed using assembly, I am now trying to do the program in C. I have a module that displays text, when it encounters a ChrEsc it gets the next byte which indicates what to do, which in this case is EscVarDis so it retrieves the address word Var1 and displays the value it contains. It then continues to display any remaining text. I created the literal string in assembly like so:
    DB “TEXT ”
    DB ChrEsc, EscVarDis
    DW Var1
    ChrEsc and EscVarDis are assembler constants and Var1 is an address.
    I want to do the same thing in C, but don’t know how to embed the data. I want to be able to call a function with the address to a literal string containing the embedded data, like so:
    DisplayString(“TEXT < ChrEsc, EscVarDis, Var1> MORE TEXT”)
    I can’t find a way of inserting ChrEsc, EscVarDis, Var1 into the string. I know you can insert control codes using \xnn, but you can’t specify a compiler label for the value nn. I have no idea how to insert the pointer value Var1. Can anyone help with this please.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    You can use sprintf to "print" a string using the same mechanism as printf. However *printf takes up a lot of room on your chip, as I understand it. You can also use memcpy or the like to build your string.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    You really can't do that directly. But you could do it by using a byte array.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism and generic lists
    By Shibby3 in forum C# Programming
    Replies: 9
    Last Post: 07-26-2010, 05:27 AM
  2. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 04:24 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM