char phrase[100];
int s;
printf("Please enter a word: ");
scanf("%s", phrase);
for (s = 0; phrase[s] != ''\0''; s++)
phrase[s] = ''_'';
printf(phrase);
printf("\n");
What I am trying to do is add a " " between each "_" but no matter what I have tried it gives a funny reponse. Also is each space represent by a "value" like the first dash is phrase[1], second is phrase[2], and so on and so on. So does the computer remember what the dash really are?? Thanks for the help
(friend) WHAT!!!!..... Are you crazy???
(me) Yes I am.
I have this problem
I have this code:
What you''re currently doing is replacing every character of phrase with a ''_''. By every iteration you print the actual value of phrase (some underscores, then the rest of the original string). Using an if would be a good starting point.
quote:Original post by librab103
I have this code:
*snip*
What I am trying to do is add a " " between each "_" but no matter what I have tried it gives a funny reponse. Also is each space represent by a "value" like the first dash is phrase[1], second is phrase[2], and so on and so on. So does the computer remember what the dash really are?? Thanks for the help
Well, your code simply replaces all the letters in the string with underscores. How could the original string possibly remember the previous values? You're completely overwriting them.
In terms of making it print spaces in between the underscores, it's probably easier to have whatever prints the word on the screen take care of that, rather than edit the string to have all these meaningless spaces in it. Something like this:
//after the above codeint c;for(c = 0; phrase[s] != '\0'; c++) //c++. get it? get it? ah, I kill me...{ printf("%c ", phrase[s]);}printf("\n");
Or instead of that, you could replace your code with:
char phrase[100]printf("Please enter a word");scanf("%s", phrase);//and then when you want to spit out the string as a sequence of underscores:int c;for(c = 0; c < strlen(phrase); c++){ printf("_ ");}printf("\n");
[edit]God, these forums are frustrating...[/edit]
[edited by - SoulSkorpion on August 10, 2003 9:30:00 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement