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. Variable argument functions- how to?

Variable argument functions- how to?

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorialquestion
4 Posts 3 Posters 2 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.
  • E Offline
    E Offline
    Ernesto D
    wrote on last edited by
    #1

    Hi all, i would like to know how to create a function that takes a variable number of arguments (parameters), you know, like the CString::Format(LPCTSTR lpszFormat, ... ). Please note that i do NOT use MFC (i use W32-API and WTL), so even if theres some class, typedef, or whatever that helps with this, but is part of MFC, it wont do me any good. Any idea of where i should start looking? Thanks!

    M P 2 Replies Last reply
    0
    • E Ernesto D

      Hi all, i would like to know how to create a function that takes a variable number of arguments (parameters), you know, like the CString::Format(LPCTSTR lpszFormat, ... ). Please note that i do NOT use MFC (i use W32-API and WTL), so even if theres some class, typedef, or whatever that helps with this, but is part of MFC, it wont do me any good. Any idea of where i should start looking? Thanks!

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      You may just code a simple console (text-mode) application, and trace into printf( ... ).


      Maxwell Chen

      1 Reply Last reply
      0
      • E Ernesto D

        Hi all, i would like to know how to create a function that takes a variable number of arguments (parameters), you know, like the CString::Format(LPCTSTR lpszFormat, ... ). Please note that i do NOT use MFC (i use W32-API and WTL), so even if theres some class, typedef, or whatever that helps with this, but is part of MFC, it wont do me any good. Any idea of where i should start looking? Thanks!

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        #include #include double average(int num, ...)
        {
        va_list arguments; //A place to store the list of arguments
        va_start(arguments, num); //Initializing arguments to store all values
        int sum=0; // passed in after num
        for(int x=0; x


        I'll write a suicide note on a hundred dollar bill - Dire Straits

        E 1 Reply Last reply
        0
        • P Prakash Nadar

          #include #include double average(int num, ...)
          {
          va_list arguments; //A place to store the list of arguments
          va_start(arguments, num); //Initializing arguments to store all values
          int sum=0; // passed in after num
          for(int x=0; x


          I'll write a suicide note on a hundred dollar bill - Dire Straits

          E Offline
          E Offline
          Ernesto D
          wrote on last edited by
          #4

          That looks simple enough, Thanks!

          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