You are here:

C++/string manipulation


For the following program, I understand how to use strlen(), but I couldn't print out a string with *.  
This is the requirement:
The function strlen() will tell you the number of characters in a string.  use a for loop to print out a string the user enters with a * between each letter.  Assume a maximum input string of 20 characters.  
input: "Charlie"
output: "C*h*a*r*l*i*e

Any suggestions?
Thank you

Hello Katrina,

This is not actually that difficult if you think about it. Something along the lines of:

// in main
int main()
char name[20] = {0};
unsigned int i;

cout << "Enter your name\n";

for(i = 0; i < strlen(name); i++)
cout << name[i] << '*';
return 0;

As you can see, that should solve that problem, assuming we are talking C++ and not C, where the input and output methods would be different.

I hope this information was helpful.

- Eddie  


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.