Hi, I have been asked to edit this code into working order, then edit it. I just cant seem to get it to compile, I'm not asking for a solution, just if you could hint at what's wrong with the below code!
This generally means that there are some errors or something, could you post those?
The things that jump out at me are:
-word is a single character, but you try assigning a string literal to it.
-"fire" is only four characters long, so what do you think word (assuming that you fixed the above) is accessing (remember that c-strings are null terminated)?
On line 7, you're declaring word to be a single character, when I think you want it to be an array of characters: char word = "fire";
The next problem is going to be, "fire" is actually 5 characters long:
word = 'f'
word = 'i'
word = 'r'
word = 'e'
word = '\0'
That last guy is what is known as a "null terminator". For C-style strings (the ones that use arrays of characters) the null terminator is how the end of the string is detected. You can't see it, but under the covers the compiler adds this terminator to string literals like "fire". However, on line 12 you're overwriting the null terminator with a newline character. So, when you go to print this, whatever is printing the stream is going to print the word, then a newline, and then it is going to keep interpreting the memory on after that until it runs into something that looks like a null terminator.