1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Printing character arrays c++

  1. Nov 19, 2009 #1
    1. The problem statement, all variables and given/known data

    I have a bunch of integers stored in a character array, and I am trying to print the integers as characters. I can print them as characters when I use %c in the print statement, but the problem is I need to print them as a string. My program crashes when I attempt to use the %s in the print statement. Can anyone help me out?


    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Nov 19, 2009 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Why are you storing numbers in character arrays? Why are you trying to print numbers with %s?

    - Warren
     
  4. Nov 19, 2009 #3

    Mark44

    Staff: Mentor

    I would just print them one at a time in a for loop. The %s format specifier is only for zero-terminated arrays of type char.
     
  5. Nov 19, 2009 #4
    Sorry I should have been more specific; the assignment I am working on is to develop a program that can cipher and decipher vigener's/ceaser ciphering.

    My function I have created receives three references of character arrays. One array stores the key word, one array stores the secret message, and one array is empty, waiting to be filled with the encrypted text; which is the job of this function.

    I had to convert the characters stored in the two arrays into their corresponding integer values in order to develop the encrypted values (using a mathematical equation) which should then be stored into the empty character array. All the values in this array correspond to letter characters which should spell out the encrypted text.

    The only problem I have is being able to convert these values back to their corresponding letter characters. I hope this clears up the problem.
     
  6. Nov 19, 2009 #5

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Can you ask a more specific question, or show us the relevant parts of your code, so that we can understand where it's crashing?

    - Warren
     
  7. Nov 20, 2009 #6

    Borek

    User Avatar

    Staff: Mentor

    What values do these integers take?
     
  8. Nov 20, 2009 #7
    We help much unless we see the code you used.
     
  9. Nov 20, 2009 #8

    Mark44

    Staff: Mentor

    And if we do see the code, we don't help at all! :wink:
     
  10. Nov 20, 2009 #9
    Help us help you help us help us all.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Printing character arrays c++
  1. Array C++ (Replies: 2)

  2. C - array (Replies: 2)

Loading...