Fgets ()
Fgets () The function is a file operation related function temporarily using this function can receive a string from the keyboard, save to the character array of the original received string saved to the array method: char str[50]; 1) scanf ("%s", str); Disadvantage: Cannot receive space 2) gets (str); Pros: Can receive a space//disadvantage: There will be an unsafe warning fgets () is a safe string to receive the function char ch[5];//If fgets is used, the maximum number of visible characters in the array is 4 // will automatically store the last element of the array. fgets () uses the format: fgets (array name, array length, stdin); For example: char ch[5] //fgets reads a string from the input buffer into a character array //when the input string is longer than the length of the array, Fgets automatically //turns the last element of the array into \ 0 //When the length of the input string is less than the length of the array, Fgets will also receive a carriage return fgets (ch,sizeof (CH), stdin); Remove the extra \ n
Fputs ()
Fputs (); is also a file operation related to the format of the function : fputs (array name, stdout); For example: fputs (ch,stdout); Fputs is output that does not wrap fputs and cannot be formatted
The biggest advantage of fgets () and fputs () is that they automatically intercept input strings, making it safe to store strings.
Fgets () function and fputs () function