# confused

• 04-29-2003
luckyboy23
confused
I have to read in from input file and if a word in that file is longer than 7 letters insert "er" after the 3 letter of that word. I started by reading the file into a cstring. I know how to find the length of the words I just cant figure out how to insert "er" into the word.

any ideas?

thanks
• 04-29-2003
vasanth
ok.. so how are you finding the length.. have any code..
• 04-29-2003
luckyboy23
Code:

``` ifIn.getline(szTemp,20,' '); iLeng=strlen(szTemp); if(iLeng==7) {   //do something }```
• 04-29-2003
Magos
Should be if(iLeng > 7) instead of if(iLeng==7) according to your description.
To merge one string at the end of another, use strcat().
• 04-29-2003
LuckY
of course there are many different ways to do it, but what I suggest is that you make use of these two functions:
strncpy() and strcat()
• 04-29-2003
luckyboy23
Code:

``` . . if (iLeng>7) {   for(int i=0; i<=2; i++)   {     ifIn>>temp[i];   }   strcat(temp,"er"); // I thought about this but i don't know what to do here```
but if i do it this way i don't know if it will work for every word in the file because if I loop this for every word in the file my "i" will be at a different point in the file.

so this is where i get confused
• 04-29-2003
ddavidson
What does Your Variable Temp[i] hold?

If length of the word >7 then
word=word+er

to make word=word+7 you can use the strcpy, strcat functions
• 04-29-2003
LuckY
Quote:

Originally posted by ddavidson
If length of the word >7 then
word=word+er

to make word=word+7 you can use the strcpy, strcat functions

Actually that won't accomplish his goal. He needs to:
Quote:

insert "er" after the 3 letter of that word
The resultant string should be src[0-2]+"er"+src[3-len]
• 04-29-2003
luckyboy23
but, how do I code it so it will work for every word in the file that I need it to. because i am clueless
• 04-29-2003
LuckY
The steps:
Code:

```1) read a word from the file 2) if word is > 7   a) copy the first 3 characters to a separate buffer   b) concatenate "er" to the separate buffer   c) concatenate the 4th to the end of the word to the separate buffer 3) do whatever else you need to do with the buffer (display it, etc) 4) repeat step 1 and continue until end of file```
• 04-30-2003
ddavidson
Ooops