简单的足球游戏——for循环的应用,输入输出函数的区别

来源:互联网 发布:windows driver kit 7 编辑:程序博客网 时间:2024/04/28 19:28
#include <stdio.h>#include <conio.h>#include <ctype.h>int main(void){int i;char key;for (i=1;i-->0;i++){key=getch();if (key == 'a'){puts("Game start!");}elseif (key == 's'){puts("pass the ball left");}elseif (key == 'd'){puts("pass the ball down");}elseif (key == 'w'){puts("pass the ball right");}elseif (key == 'e'){puts("take the ball forward");}elseif (key == 'r'){puts("shoot the ball! ---------------------Goal");}}return 0;}
C中的PUTS函数只用来输出字符串,没有格式控制,它里面的参数就是存放字符串的字符数组的数组名就可以了,PRINTF函数输出格式有很多,类型也不用说了,可以根据不同格式加些转义字符以达到格式华的输出,比如换行,制表等等....


puts(str) //str为一字符串则自动在str的后面加一个换行符\n而printf(str)则需要手动加上\n同理,gets接收字符串时,会将字符串后面的\n去掉,而用scanf接收时,会在字符串后面加上\n所以,puts要和gets搭配,scanf和printf搭配使用。

0 0
原创粉丝点击