why dose this only give me:Code:deleted
ouput is:
not
Output is: <somthing here>
why dose this only give me:Code:deleted
ouput is:
not
Output is: <somthing here>
Last edited by IM back!; 09-05-2008 at 11:40 AM.
You never change output[0], since runoften is at least 1 before you get to anywhere in your "input parsing routine" -- and if output[0] happens to be \0, then your string ends before it even gets started.
(I put "input parsing routine" in quotes because it's not clear that you mean to be skipping all those letters -- when runoften increases two or three or four at a time, you're going to be skipping two or three or four input characters. And I also really hope you have indentation in your source file, or else eeesh.)
And:
is absolutely meaningless. Assigning a variable to itself is NEVER meaningfull [1]Code:runoften=runoften;
[1] If it's a pointer to a hardware register then it may have a meaning (e.g. writing bits that are set will actually clear those bits in some hardware registers).
And would it not make more sense to have a function that produces N stars followed by the symbol X?
Further, instead of having a huge number of if-statements, use a switch-case [or at least use if-else-if chains, since if the letter is 'a', then it's obviously NOT going to be equal to 'b'.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Code:int aa; int bb; string name; char input[1000]; char output[1000]; void a { while (aa != 100) { cout<<"loop"; aa=aa+1; if(input[aa]=='a'||input[aa]=='d'||input[aa]=='g'||input[aa]=='j'||input[aa]=='m'||input[aa]=='p'||input[aa]=='s'||input[aa]=='w') { input[aa]='*'; } else { if(input[aa]=='b'||input[aa]=='c'||input[aa]=='d'||input[aa]=='e'||input[aa]=='f'||input[aa]=='g'||input[aa]=='t'||input[aa]=='x') { output[aa]='*'; bb=aa; bb++; output[bb]='*'; bb=0; } else { output[aa]='*'; bb=aa; bb++; output[bb]='*'; bb++; output[bb]='*'; bb=0; } } } cout<<output; }
Last edited by IM back!; 09-05-2008 at 11:39 AM.
I only read that dubious line and didn't even bother going further ahead. You need that to be broken into multiple conditions. Or'ing those together is not at all doing what you want.Code:if(input[aa]='a'|'d'|'g'|'j'|'m'|'p'|'s'|'w')
Well, 'a'|'d'|'g'|'j'|'m'|'p'|'s'|'w' is some large number, you then assign it to input[aa] (not comparison, mind you, but assignment), and then output[1] is set to *.Code:input[aa]='a'|'d'|'g'|'j'|'m'|'p'|'s'|'w'
(And continues etc.)
Then when you go to print output, it starts at output[0], finds that that is the null character, and stops (because that's how strings work -- they go until you get a null character and then you stop).
Are those supposed to be ORs? If so, that's not how it works.Code:if(input[aa]='a'|'d'|'g'|'j'|'m'|'p'|'s'|'w')
Code:if (input[aa] == 'a' || input[aa] == 'd' || input[aa] == 'g' ...
OK thank you all, I still have a lot to learn , I made some corrections. now how do I get the to print the output
Fantastic! I am glad you are at least halfway getting it now. Next time don't be so ashamed by your initial post that you delete the code, however. Believe it or not, others will probably one day ask the same question and benefit from seeing someone who asked it in a similar way. Right?
OK thanks now it works i simply defined aa like this int aa = -1;
Wow... I didn't even notice that it was uninitialized. You should put those as local variables, by the way. There is no earthly reason for them to exist outside of your function.
> if (input[aa] == 'a' || input[aa] == 'd' || input[aa] == 'g' ...
To improve further, consider
if ( strchr( "adg", input[aa] ) )
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
thats because that is a part of a small app, I could have done it like this. operation(char input[100], int aa) but i find global variables easyer in this case.
now one last qusetion: why dose this not work:
I also tryed:Code:if(input[aa]==' ') { output[bb]='0'; bb++; }
since 32 is the acsii code for "space" i think.Code:if(input[aa]==32) { output[bb]='0'; bb++; }