How can I print integers as a string in C++ using character arrays?

  • Context: Comp Sci 
  • Thread starter Thread starter sdoug041
  • Start date Start date
  • Tags Tags
    Arrays C++ Printing
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
8 replies · 4K views
sdoug041
Messages
25
Reaction score
0

Homework Statement



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?


Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
Why are you storing numbers in character arrays? Why are you trying to print numbers with %s?

- Warren
 
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.
 
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.
 
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
 
What values do these integers take?
 
We help much unless we see the code you used.
 
Lancelot59 said:
We help much unless we see the code you used.
And if we do see the code, we don't help at all! :wink:
 
Help us help you help us help us all.