A program that will create scrambled words by circularly rotating the middle characters of each word by 1 character. Place the scrambled words, 1 per line in an output file.
Example:
hamster becomes hmstear
Sample input file:
4
dog
pepper
marker
teapot
Sample output file:
dog
pppeer
mrkear
tapoet

Recommended Answers

All 3 Replies

Post the code you have written so that someone can help you with any questions you may have. No one is going to just give you the solution to the program.

Like what Ancient Dragon said, but I can give you some hints.

C style strings are pointers to characters, assuming you will be using <string.h> you will have the ability to use strlen( char *c )

strlen returns the length of the string, which you will need to know so you don't mess up the last character.

you will also need a tmp variable to keep track of the second letter of the string. lastly you will need to run a loop to move each character forward one space in the string. then the second to last character will equal what was the original character.

Good luck!

C style strings are pointers to characters

Add "sometimes" in there any I'll agree with you. The definition of a string in C is a contiguous sequence of zero or more characters terminated by '\0'. That means you can represent a string with an array (note that arrays are not pointers), or with a pointer to the first character in a block of memory that matches the definition.

The reason I mention this is because it causes a lot of confusion, and I think it's imporant in this case to be pedantic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.