Printing a string in C using a function -


I'm new to C and trying to print a string and print it using a function. I see examples everywhere by using = 0) as a function (instead of the main () for example, but to do this work Right now, it is stuck in an endless loop ... why is it so?

// 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:

  1. reads characters from stdin
  2. Stdin stores the first letter read in the first letter From ch (This might not work if you pass in the string.
  3. writes stdout to the characters.
  4. 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