Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. passing string as first parameter in sprintf

passing string as first parameter in sprintf

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiran Pinjala
    wrote on last edited by
    #1

    Hi, Can I pass a string with some %s in it as first parameter in printf/sprintf. something like bellow

    char str[16]="my name is %s";
    char name[8]="xman";
    char res[24];
    sprintf(res,str,xman);
    printf("%s",res);

    can we achieve this?

    Saadhinchaali

    M L V S D 5 Replies Last reply
    0
    • K Kiran Pinjala

      Hi, Can I pass a string with some %s in it as first parameter in printf/sprintf. something like bellow

      char str[16]="my name is %s";
      char name[8]="xman";
      char res[24];
      sprintf(res,str,xman);
      printf("%s",res);

      can we achieve this?

      Saadhinchaali

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, Have a look at the vsprintf, vswprintf[^] functions. Best Wishes, -David Delaune

      K 1 Reply Last reply
      0
      • K Kiran Pinjala

        Hi, Can I pass a string with some %s in it as first parameter in printf/sprintf. something like bellow

        char str[16]="my name is %s";
        char name[8]="xman";
        char res[24];
        sprintf(res,str,xman);
        printf("%s",res);

        can we achieve this?

        Saadhinchaali

        M Offline
        M Offline
        Madhu Nair 0
        wrote on last edited by
        #3

        Don't have access to a PC right now ? :^)

        1 Reply Last reply
        0
        • K Kiran Pinjala

          Hi, Can I pass a string with some %s in it as first parameter in printf/sprintf. something like bellow

          char str[16]="my name is %s";
          char name[8]="xman";
          char res[24];
          sprintf(res,str,xman);
          printf("%s",res);

          can we achieve this?

          Saadhinchaali

          V Offline
          V Offline
          Vincen Wang
          wrote on last edited by
          #4

          of course

          You know some birds are not meant to be caged, their feathers are just too bright.

          1 Reply Last reply
          0
          • K Kiran Pinjala

            Hi, Can I pass a string with some %s in it as first parameter in printf/sprintf. something like bellow

            char str[16]="my name is %s";
            char name[8]="xman";
            char res[24];
            sprintf(res,str,xman);
            printf("%s",res);

            can we achieve this?

            Saadhinchaali

            S Offline
            S Offline
            suthakar56
            wrote on last edited by
            #5

            sprintf(res,str,xman);

            here xman is undeclared identifier..

            M 1 Reply Last reply
            0
            • S suthakar56

              sprintf(res,str,xman);

              here xman is undeclared identifier..

              M Offline
              M Offline
              Michael Schubert
              wrote on last edited by
              #6

              suthakar56 wrote:

              here xman is undeclared identifier..

              What do you expect? You did not declare that variable.

              1 Reply Last reply
              0
              • K Kiran Pinjala

                Hi, Can I pass a string with some %s in it as first parameter in printf/sprintf. something like bellow

                char str[16]="my name is %s";
                char name[8]="xman";
                char res[24];
                sprintf(res,str,xman);
                printf("%s",res);

                can we achieve this?

                Saadhinchaali

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Tritva wrote:

                can we achieve this?

                Have you tried?

                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                1 Reply Last reply
                0
                • L Lost User

                  Hi, Have a look at the vsprintf, vswprintf[^] functions. Best Wishes, -David Delaune

                  K Offline
                  K Offline
                  Kiran Pinjala
                  wrote on last edited by
                  #8

                  thank you David. It solved my problem

                  Saadhinchaali

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups