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. How to insert a "," in an array?

How to insert a "," in an array?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdata-structuresquestion
3 Posts 3 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.
  • U Offline
    U Offline
    User 1990498
    wrote on last edited by
    #1

    Hi does anyone know how to insert commas in array? example: 2,3 3,3 4,2 I need to show these commas when I execute the program. Pls advice.

    C 1 Reply Last reply
    0
    • U User 1990498

      Hi does anyone know how to insert commas in array? example: 2,3 3,3 4,2 I need to show these commas when I execute the program. Pls advice.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      for (int i = 0; i < arraySize-1; ++i) { cout << array[i] << ", "; } cout << array[arraySize-1]; Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        for (int i = 0; i < arraySize-1; ++i) { cout << array[i] << ", "; } cout << array[arraySize-1]; Christian Graus - Microsoft MVP - C++

        J Offline
        J Offline
        Jose Lamas Rios
        wrote on last edited by
        #3

        Christian Graus wrote: for (int i = 0; i < arraySize-1; ++i) { cout << array[i] << ", "; } cout << array[arraySize-1]; Right, but don't forget to test for the empty array condition. The for loop checks it itself, but the last sentence may attempt to access array[-1]. -- jlr http://jlamas.blogspot.com/[^]

        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