Monday, May 24, 2010

C++ strings?

Hey! do you know what is this instruction doing... I mean, the ++ after the string...





for (i=0;i %26lt; strlen(texto);i++)


contadores[texto[i]]++;





THANKS!

C++ strings?
Looks to me like you've got an array called "contadores" which is, if I'm not mistaken, "counters" in Spanish.





texto[i] is going to be the i'th character in the string.


if it's, say, an uppercase A, then the 65 element of contadores will be incremented (have one added to it)





Voy a tratar de traducir estos instrucciones a espanol:


Parece que tiene un array (?) que se llama "contadores"


El valor de texto[i] va a ser la character en posision "i" en el string. Si es "A" entonces el elemento en posision 65 va a ser mejorado por uno.





Hope that helps.





It's really hard for me to talk about programming in Spanish.
Reply:increase the char "contadores" at the postition specified by texto[i], increase only 1 such as from 'a' to 'b'. Just like that.





suggess you trying to see its result by using printf to show what happen before and after this instruction, you'll know how it works.
Reply:The ++ increments whatever is before it, the value in contadores[texto[i]] in this case.
Reply:The ++ in contadores[texto[i]]++ will increment the value that the array contadores holds. If contadores is an array of characters it will increment the value it hold - i.e. if contadores[texto[i]] = 'a', contadores[texto[i]]++ will turn 'a' into 'b'.
Reply:in this for loop, i is being start from 0 and incrementing by one(i++) so it must go to 1 ine next iteretion


but it will jump to 2 not to 1


because in next line( contadores[text[i]]++ ) you are incremneting again so it will skip one step so use i+1 instead of i++in next line.
Reply:so your program will find the frequency of the characters...


ie.,for example if, texto has "sriram" then your countadores will increment the respective (ascii) positions.





as my previous person answered...





thanks

deliver flowers

No comments:

Post a Comment