I'm new to C and trying to print a string and print it using a function. I see examples everywhere by using
// to main (): // printString ("hello"); Zero print string (four * ch) {while (* ch = getchar (), * ch> = 0) Tutor (* ch); }
Depending on your description, you just want:
< Pre> zero print string (char * ch) {while (* ch) {putchar (* ch); Ch ++; }}
Your original work:
zero printstring (four * ch) {while (* ch = getchar (), * ch> = 0) Fur (* f); }
There are a lot of things:
- reads characters from stdin
- Stdin stores the first letter read in the first letter From
ch
(This might not work if you pass in the string. - writes stdout to the characters.
- When the letter is read & Lt; 0 (This will not work on some platforms.Because the result is stored in an axis, you can not distinguish between EOF and a valid character. Ch is an integer , Because getchar () gives an int to enable you to check EOF)
Comments
Post a Comment