📄 fp.htm
字号:
<BR>
<P>函数名: putc
<BR>功 能: 输出一字符到指定流中
<BR>用 法: int putc(int ch, FILE *stream);
<BR>程序例:
<P>#include <stdio.h>
<P>int main(void)
<BR>{
<BR> char msg[] = "Hello world\n";
<BR> int i = 0;
<P> while (msg[i])
<BR> putc(msg[i++], stdout);
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: putch
<BR>功 能: 输出字符到控制台
<BR>用 法: int putch(int ch);
<BR>程序例:
<P>#include <stdio.h>
<BR>#include <conio.h>
<P>int main(void)
<BR>{
<BR> char ch = 0;
<P> printf("Input a string:");
<BR> while ((ch != '\r'))
<BR> {
<BR> ch = getch();
<BR> putch(ch);
<BR> }
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: putchar
<BR>功 能: 在stdout上输出字符
<BR>用 法: int putchar(int ch);
<BR>程序例:
<P>#include <stdio.h>
<P>/* define some box-drawing characters */
<BR>#define LEFT_TOP 0xDA
<BR>#define RIGHT_TOP 0xBF
<BR>#define HORIZ 0xC4
<BR>#define VERT 0xB3
<BR>#define LEFT_BOT 0xC0
<BR>#define RIGHT_BOT 0xD9
<P>int main(void)
<BR>{
<BR> char i, j;
<P> /* draw the top of the box */
<BR> putchar(LEFT_TOP);
<BR> for (i=0; i<10; i++)
<BR> putchar(HORIZ);
<BR> putchar(RIGHT_TOP);
<BR> putchar('\n');
<P> /* draw the middle */
<BR> for (i=0; i<4; i++)
<BR> {
<BR> putchar(VERT);
<BR> for (j=0; j<10; j++)
<BR> putchar(' ');
<BR> putchar(VERT);
<BR> putchar('\n');
<BR> }
<P> /* draw the bottom */
<BR> putchar(LEFT_BOT);
<BR> for (i=0; i<10; i++)
<BR> putchar(HORIZ);
<BR> putchar(RIGHT_BOT);
<BR> putchar('\n');
<P> return 0;
<BR>}
<BR>
<BR>
<P>函数名: putenv
<BR>功 能: 把字符串加到当前环境中
<BR>用 法: int putenv(char *envvar);
<BR>程序例:
<P>#include <stdio.h>
<BR>#include <stdlib.h>
<BR>#include <alloc.h>
<BR>#include <string.h>
<BR>#include <dos.h>
<P>int main(void)
<BR>{
<BR> char *path, *ptr;
<BR> int i = 0;
<P> /* get the current path environment */
<BR> ptr = getenv("PATH");
<P> /* set up new path */
<BR> path = malloc(strlen(ptr)+15);
<BR> strcpy(path,"PATH=");
<BR> strcat(path,ptr);
<BR> strcat(path,";c:\\temp");
<P> /* replace the current path and display current environment
*/
<BR> putenv(path);
<BR> while (environ[i])
<BR> printf("%s\n",environ[i++]);
<P> return 0;
<BR>}
<BR>
<BR>
<P>函数名: putimage
<BR>功 能: 在屏幕上输出一个位图
<BR>用 法: void far putimage(int x, int y, void far *bitmap, int
op);
<BR>程序例:
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<P>#define ARROW_SIZE 10
<P>void draw_arrow(int x, int y);
<P>int main(void)
<BR>{
<BR> /* request autodetection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> void *arrow;
<BR> int x, y, maxx;
<BR> unsigned int size;
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<P> maxx = getmaxx();
<BR> x = 0;
<BR> y = getmaxy() / 2;
<P> /* draw the image to be grabbed */
<BR> draw_arrow(x, y);
<P> /* calculate the size of the image */
<BR> size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
<P> /* allocate memory to hold the image */
<BR> arrow = malloc(size);
<P> /* grab the image */
<BR> getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE,
arrow);
<P> /* repeat until a key is pressed */
<BR> while (!kbhit())
<BR> {
<BR> /* erase old image */
<BR> putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
<P> x += ARROW_SIZE;
<BR> if (x >= maxx)
<BR> x = 0;
<P> /* plot new image */
<BR> putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
<BR> }
<P> /* clean up */
<BR> free(arrow);
<BR> closegraph();
<BR> return 0;
<BR>}
<P>void draw_arrow(int x, int y)
<BR>{
<BR> /* draw an arrow on the screen */
<BR> moveto(x, y);
<BR> linerel(4*ARROW_SIZE, 0);
<BR> linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
<BR> linerel(0, 2*ARROW_SIZE);
<BR> linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
<BR>}
<BR>
<BR>
<P>函数名: putpixel
<BR>功 能: 在指定位置画一像素
<BR>用 法: void far putpixel (int x, int y, int pixelcolor);
<BR>程序例:
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>#include <dos.h>
<P>#define PIXEL_COUNT 1000
<BR>#define DELAY_TIME 100 /* in milliseconds */
<P>int main(void)
<BR>{
<BR> /* request autodetection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int i, x, y, color, maxx, maxy, maxcolor, seed;
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<P> maxx = getmaxx() + 1;
<BR> maxy = getmaxy() + 1;
<BR> maxcolor = getmaxcolor() + 1;
<P> while (!kbhit())
<BR> {
<BR> /* seed the random number generator
*/
<BR> seed = random(32767);
<BR> srand(seed);
<BR> for (i=0; i<PIXEL_COUNT; i++)
<BR> {
<BR> x = random(maxx);
<BR> y = random(maxy);
<BR> color = random(maxcolor);
<BR> putpixel(x, y, color);
<BR> }
<P> delay(DELAY_TIME);
<BR> srand(seed);
<BR> for (i=0; i<PIXEL_COUNT; i++)
<BR> {
<BR> x = random(maxx);
<BR> y = random(maxy);
<BR> color = random(maxcolor);
<BR> if (color == getpixel(x, y))
<BR> putpixel(x, y, 0);
<BR> }
<BR> }
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: puts
<BR>功 能: 送一字符串到流中
<BR>用 法: int puts(char *string);
<BR>程序例:
<P>#include <stdio.h>
<BR>int main(void)
<BR>{
<BR> char string[] = "This is an example output string\n";
<P> puts(string);
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: puttext
<BR>功 能: 将文本从存储区拷贝到屏幕
<BR>用 法: int puttext(int left, int top, int right, int bottom,
void *source);
<BR>程序例:
<P>#include <conio.h>
<BR>int main(void)
<BR>{
<BR> char buffer[512];
<P> /* put some text to the console */
<BR> clrscr();
<BR> gotoxy(20, 12);
<BR> cprintf("This is a test. Press any key to continue
...");
<BR> getch();
<P> /* grab screen contents */
<BR> gettext(20, 12, 36, 21,buffer);
<BR> clrscr();
<P> /* put selected characters back to the screen */
<BR> gotoxy(20, 12);
<BR> puttext(20, 12, 36, 21, buffer);
<BR> getch();
<P> return 0;
<BR>}
<BR>
<BR>
<P>函数名: putw
<BR>功 能: 把一字符或字送到流中
<BR>用 法: int putw(int w, FILE *stream);
<BR>程序例:
<P>#include <stdio.h>
<BR>#include <stdlib.h>
<P>#define FNAME "test.$$$"
<P>int main(void)
<BR>{
<BR> FILE *fp;
<BR> int word;
<P> /* place the word in a file */
<BR> fp = fopen(FNAME, "wb");
<BR> if (fp == NULL)
<BR> {
<BR> printf("Error opening file %s\n", FNAME);
<BR> exit(1);
<BR> }
<P> word = 94;
<BR> putw(word,fp);
<BR> if (ferror(fp))
<BR> printf("Error writing to file\n");
<BR> else
<BR> printf("Successful write\n");
<BR> fclose(fp);
<P> /* reopen the file */
<BR> fp = fopen(FNAME, "rb");
<BR> if (fp == NULL)
<BR> {
<BR> printf("Error opening file %s\n", FNAME);
<BR> exit(1);
<BR> }
<P> /* extract the word */
<BR> word = getw(fp);
<BR> if (ferror(fp))
<BR> printf("Error reading file\n");
<BR> else
<BR> printf("Successful read: word
= %d\n", word);
<P> /* clean up */
<BR> fclose(fp);
<BR> unlink(FNAME);
<P> return 0;
<BR>}
<BR>
<P>
<A HREF="index.html">返回目录</A>
<BR>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -