getchar uses round parentheses not square brackets to hold the parameters.
you don't need the & address operator on line 26 because arrays are ALWAYS passed by address.
line 28 has a couple problems: if you only want one character then use "%c" instead of "%s". and it has the same problem as above on line 26.
line 31: The double quote immediately after '%c should be a single quote. The rest of the errors will be fixed too when you correct that.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
what have YOU tried to fix the problems? Look at the error messages, they tell you what lines are incorrect. Then look up the function in your textbook or online and see why the compiler says you are wrong.
line 13 is wrong -- what is the value of string when it first enters that loop ? Hint: its value is just some random junk because you didn't initialize it to anything. And even if you did initialize it that line would still be wrong.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Why is LetterToMatch defined as an array of one char? Why not just define it as a char and it won't be a pointer, correcting some of the errors.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>if ( i >= 'LetterToMatch')
I'm going to go out on a limb and guess that you meant:
if ( i == LetterToMatch )
LetterToMatch is a variable, and you're checking to see if i matches it, correct? Also, if you're going to test against LetterToMatch, you need to make sure that it's actually been set to something.
>does anyone know what EOF is supposed mean?
It's supposed to mean end-of-file, or "you've reached the end of the data".
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>I'm guessing that because you said this that LetterToMatch is not set to anything?
Good guess. If you don't set it to anything, then it really could be anything. If you know the character you're going to look for at compile time, then it's trivial. Just do this:
char LetterToMatch = 'A'; /* Assuming you want to find 'A' */
If it's a runtime value that you get from the user, you'd do this instead:
char LetterToMatch;
printf ( "Enter a letter to search for: " );
fflush ( stdout );
LetterToMatch = getchar();
>Another thing I'm having trouble grasping is what exactly (i = getchar() ) is telling the program
getchar is easy. It returns the next character from stdin and returns EOF if it fails to do so for any reason. So if you say this:
int ch;
while ( ( ch = getchar() ) != EOF )
putchar ( ch );
You're reading characters from stdin (and writing them in that order to stdout) until getchar fails. Assuming you're on a Windows machine, you can signal EOF by typing ctrl+z (that's holding down either ctrl key and then pressing z).
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>I don't think we've learned fflush yet, so I don't think we can use it
You probably don't fflush yet, and this explanation may be too much, but store it away for later use:
To be strictly correct and portable, you should flush stdout manually for any user prompt unless you print a '\n' character, because the message might not be visible until the stream is flushed. If you don't print '\n' or call fflush, you have to rely on the buffer being filled up, which could happen at different times depending on your compiler.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401