#include #define MAXLINE 20int main (void){Char Line[maxline];while (Fgets (Line,maxline,stdin)!=null && line[0]! = ' \ n ')Fputs (line,stdout);return 0;}The fgets () function is the address (char * type) used to store the input. The second argument
1 function input
The following two functions provide the function of inputting a row at a time.
# Include char * fgets (char * restrict Buf, int N, file * restrict FP); char * gets (char * BUF); two function return values: If successful, the return
fprintf
,
fputs
,
FPUTC
the speed of comparisonMany friends write the program, the output function is used to use printf, and the following two functions are rarely used, the main reason is probably because printf general strong, function
It's been a long time, not a series.
string Read and write functions fgets and fputs:
1, fgets () function:Prototype Char *fgets (char *s, int n, FILE *stream);read out before reading the n-1 (n default 1024) character from the stream, such as if a
First, puts () function of the detailedThe puts () function is used to write a string to a standard output device (screen) and wrap it in a format called:
puts (s);
where S is a string variable (string array name or string pointer).The
Http://hi.baidu.com/dujt/blog/item/f6e6704ab5d8932508f7ef2c.html
In ansi c, file operations are divided into two methods: stream file operations and I/O file operations, which are described below.
I. Stream File OperationsThis file operation has an
Format: int fgetc (File * stream );
Indicates reading a character from the object pointed to by the file pointer stream.
The return value of this function is a byte read.. If EOF is returned at the end of the file.
The prototype is char *
C language fgets fputs fgets () reads a string from a fileheader files: #include function Prototype: char * fgets (char * s, int size, FILE * stream)function Description: reads a string from a file pointed to by the file pointer stream and saves it
Lesson NOTES: Strings stored in the C language (arrays and pointers) 1. Use a character array to store1 Char name[5] = {' J ', ' A ', ' C ', ' K '}; 2 char name[] = {' J ', ' A ', ' C ', ' K '}; 3 Char // only when the character array is directly
"Mastering" fget (), fputs () function use/pros and cons 1, fgets () The function a file operation-related function temporarily uses this function to receive a string from the keyboard quotient, saving to the array the method that originally
Http://blog.sina.com.cn/s/blog_61437b3b0102v0bt.htmlhttp://blog.csdn.net/chenwk891/article/details/8776479 in c\c++, the file operations are implemented by the library function, mainly divided into two types of read and write operations, the
C language Fputc () function: Write file function (writes a specified character to the file stream)
Header file:
#include
To define a function:
int FPUTC (int c, FILE * stream);
Function Description: FPUTC will convert parameter
The C language has three standard library functions that are bold to output strings puts () fputs () printf ()
The use of the puts () function is simple and requires only the address of the string parameter. Note that each string is displayed in a
fprintf fputs function Use
When using the fprintf and fputs functions at the outset, the data is continuously written to the cache in a loop and then written to the file
Check the Input.txt file when it is always written in the first thought
/*Function Name: fputcFunction: Send a character to a streamUsage: int fputc (int ch, file * stream );Program example:*/# Include
Int main (){Char MSG [] = "Hello World ";Int I = 0;
While (MSG [I]){Fputc (MSG [I], stdout );I ++;}Return 0;}
Fputs
Int fputs (const char * STR, file * stream );
Write string to stream
Writes the string pointedStrToStream.The function begins copying from the address specified (Str) Until it reaches the terminating null character ('/0'). This final
# Include # define Max 81int main () {char name [Max]; char * PTR; printf ("Hi, what is your name? \ N "); PTR = fgets (name, Max, stdin); printf (" % s? Ah! % S! \ N ", name, PTR); Return 0;}/* Because fgets stores the linefeed in the string, the *
/** Database function fgets * char * fgets (char * line, int maxline, FILE * fp); * fp reads the next input line from the FILE (including line breaks ), and store it in the character array; * a row can read a maximum of maxline-1 characters, the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.