The reason is that you are only reading in one "word" with the %s format specifier. You could switch to use the %c format specifier, but it may be easier to just use fgets() as bvkim demonstrated.Originally Posted by neo28
Why do you have the found variable? You do not need it, and your attempts to use it seem to be confusing you. For example, you are still breaking from the loop after finding the first 'm'.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
well then, here the completed version following neo28 demand:
Code:#include <stdio.h> #include <string.h> #define MAX_BUFFER 256 int main( void ) { char text[ MAX_BUFFER ] = { '\0' }; int counter = 0; printf( "Please enter a string: " ); fgets( text, MAX_BUFFER, stdin ); for( ; counter < strlen( text ); ++counter ) { if( text[ counter ] == 'm' ) text[ counter ] = 'S'; } printf( "Modified: %s\n", text ); return 0; }
bvkim, let people do their own homework.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Hey guys,
Thanks for all the help, It wasn't homework, I'm just trying to learn C in general and found I learn more by trying to write a program and edit it to do simple things than read through books all the time !
Most schools have tutor assistance. I realy don't understand why they don't use them. Just the over-all laziness?
And truely it hurts none to give simple solutions to simple problems. A beginner programmer really needs a base in which to build upon. So ramming their heads against the wall over something simple isn't really correct. Its when they come back with nearly the same problems and still don't know how to do them, you should ram them in the head.
Last edited by strickyc; 05-16-2009 at 09:51 AM.
Yes, it is usually fine to give a "model answer" after you judge that the question asker has tried hard enough, or to give a working example that does not directly answer the question. In this case, neo28 was so close to a correct solution that giving one takes away from neo28's satisfaction of solving the problem himself/herself when it is just within reach.Originally Posted by strickyc
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)