① 怎样用c语言获取屏幕上指定位置处的字符的值
一、屏幕操作函数
1. clrscr()清除字符窗口函数
2. window()字符窗口函数
3. gotoxy()光标定位函数
4. clreol() 清除光标行尾字符函数
5. insline() 插入空行函数
6. delline() 删除一行函数
7. gettext() 拷进文字函数
8. puttext() 拷出文字函数
9. movetext() 移动文字函数
二、字符属性函数
10. textmode() 文本模式函数
11. highvideo()高亮度函数
12. lowvideo() 低亮度函数
13. normvideo(void);
14. textcolor() 文本颜色函数
15. textattr() 文本属性函数
16.textbackground() 文本背景函数
三、 屏显状态函数
17. wherex() 光标处x坐标函数
18. wherey() 光标处y坐标函数
19. gettextinfo() 获取文本窗口信息函数
2. window()字符窗口函数
功能: 函数window()用于在指定位置建立一个字符窗口。
用法: 此函数调用方式为 void window(int left,int top,int right,int bottom);
说明: 函数中参数left,top为窗口左上角坐标;right,bottom为其右下角坐标。
若有一个坐标是无效的,则window()函数不起作用。一旦该函数调用成功,那么所有定位坐标都是相对于窗口的,而不是相对于整个屏幕。但是建立窗口所用的坐标总是相对整个屏幕的绝对坐标,而不是相对当前窗口的相对坐标。这样用户就可以根据各种需要建立多个互不嵌套的窗口。
此函数的头文件为conio.h。
返回值:无
例: 调用这个函数的实现例见3.gotoxy()函数的例子中。
. gotoxy()光标定位函数
功能: 函数gotoxy()将字屏幕上的光标移到当前窗口指定的位置上。
用法: 这个函数调用方式为void gotoxy(int x,int y);
说明: 括号里x,y是, 光标定位的坐标,如果其中一个坐标值无效(如坐标超界),那么光标不会移动。
此函数在字符状态(有时称为文本状态)下经常用到 ,其相应的头文件为conio.h
返回值:无
例: 下面程序建立两个窗口,然后在窗口里显示字符,字符的位置是调用该函数确定的。
#include"conio.h>
void border(int startx,int starty,int endx,int endy)
{
register int i;
gotoxy(1,1);
for(i=0;i<=endx-startx;i++)
putch('-');
gotoxy(1,endy-starty);
for(i=0;i<=endx-startx;i++)
putch('-');
for(i=2;i<=endy-starty;i++){
gotoxy(1,i);
putch('1');
gotoxy(endx-startx+1,i);
putch('1');
}
}
main()
{
void border(int,int,int,int);
clrscr();
window(6,8,38,12);
border(6,8,38,12);
gotoxy(2,2);
printf("window 1");
window(8,16,40,24);
border(8,16,40,24);
gotoxy(3,2);
printf("window 2");
getch();
}
三、 屏显状态函数
这里提供三个在文本模式下屏幕显示状态的函数
17. wherex() 光标处x坐标函数
功能: 函数wherex()返回当前窗口中光标处横向坐标。
用法: 此函数调用方式为int wherex(void);
说明: 这个函数调用无参数,其对应的头文件是conio.h
返回值: 函数调用成功,返回光标处x坐标值。
例: 调用这个函数的实例见18.wherey()函数的例中。
18. wherey() 光标处y坐标函数
功能: 函数wherey()返回当前窗口中光标处纵向坐标。
用法: 该函数调用方式为int wherey(void);
说明: 此函数调用无参数,其相应的头文件是conio.h
返回值: 函数调用成功,返回光标处y坐标值。
例: 调作函数wherex()与wherey(),返回当前光标处x坐标与y坐标,并赋给整型变量xpos ,ypos。
int xpos,ypos;
xpos=wherex();
ypos=wherey();
19. gettextinfo() 获取文本窗口信息函数
功能: 函数gettextinfo()获取当前文本窗口信息,并存放在实参结构中。
用法: 函数调用方式为void gettextinfo(struct text-info *info);
说明: 函数中参数info 为struct text-info结构型指针,struct text-info结构在此函数相应的头文件中定义为:
struct text-info{
unsigned char winleft; // 窗口左上角x坐标
unsigned char wintop; // 窗口左上角y坐标
unsigned char winright; // 窗口右下角x坐标
unsigned char winbottom; // 窗口右下角y坐标
unsigned char attribute; // 文本属性
unsigned char normattr; // 正常属性
unsigned char currmode; // 当前屏显模式
unsigned char screenhight // 文本窗口高度(以行数计)
unsigned char screenwidth; // 文本窗口宽度(以字符个数计)
unsigned char curx; // 光标处x坐标
unsigned char cury; // 光标处y坐标
};
记住,调用函数gettextinfo()时,要传递struct text-info结构型指针或该结构的首地址,不要传递结构变量本身。
这个函数对应的头文件是conio.h
返回值: 返回文本窗口角点坐标、高宽度、文本属性等值,并存放在info所指向的结构变量中。
例: 程序语句说明如何正确调用gettextinfo()函数:
struct text-info win-status;
gettextinfo(&win-status);
② C语言中怎么显示文件的内容在屏幕上
1、首先第一步,你打开软件,第一行代码要写头文件,我们写的是#include<stdio.h>,在这个头文件里包含了我们要调用的函数。
③ 怎样用C语言获取屏幕上指定位置处的字符的值
很简单吧,呵呵。注意那个字符串里面是有转义字符
\
哦
#include<stdio.h>
#include<stdlib.h>
void
main()
{
char
*string1
=
"abc\\123\\web\\@cn";
char
*p
=
null;
int
n
=
strlen(string1);
int
i;
i
=
n;
if(p
==
null)
{
p
=
(char
*)malloc(n*sizeof(char
*));
}
printf("%s\n",string1);
for(p
=
string1;*p!='\0';p++)
;
p--;//使p指向最后一个位置。
for(i;i>0;i--)
{
if(*p
==
'\\')
break;
p--;
}
n
=
i;
printf("出现的最后一个位置是%d\n",n);
if(p
!=
null)
{
p
=
null;
free(p);
}
}
④ 用C语言如何将屏幕上所显示的内容全部保存到txt文件中
鼠标右击输出的窗口,点标记,然后用鼠标画框,然后敲一下回车,然后粘贴到记事本就行了
⑤ C语言编程:从键盘输入两个实数后,屏幕显示菜单如下内容
#include<stdio.h>
char *Text[] = {"退出", "两数之和",
"两数之差", "两数乘积",
"两数相乘之商"};
int main(void)
{
double n1, n2, result;
int choice;
printf("请输入两个实数:");
scanf("%lf%lf", &n1, &n2);
while(1)
{
for(int i = 1; i < sizeof(Text)/sizeof(char *); i++)
printf("%d.%s%s ", i, "输出", Text[i]);
printf("5.%s ", Text[0]);
printf("请输入你的选择: ");
scanf("%d", &choice);
if(choice == 5)
{
printf("退出关闭程序 ");
return 0;
}
if(choice < 0 || choice > 4)
{
printf("抱歉,查无此选项 ");
continue;
}
switch(choice)
{
case 1:
{
result = n1 + n2;
break;
}
case 2:
{
result = n1 - n2;
break;
}
case 3:
{
result = n1 * n2;
break;
}
case 4:
{
result = n1 / n2;
break;
}
}
printf("%s%s:%.2lf ", Text[choice], "为", result);
}
return 0;
}
⑥ C语言屏幕输出的内容如何保存到文件中
C语言中用流替换函数freopen可以从文件中读取数据或将数据输出到文件中。
需要引用库"stdio.h",即
#include<stdio.h>
freopen的声明如下:
FILE *freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream);
形参说明:
filename:需要重定向到的文件名或文件路径。
mode:代表文件访问权限的字符串。例如,"r"表示“只读访问”、"w"表示“只写访问”、"a"表示“追加写入”。
stream:需要被重定向的文件流。
返回值:如果成功,则返回该指向该输出流的文件指针,否则返回为NULL。
用法:
将输入流从stdin替换成指定文件可以从文件中读取数据;
将输出流从stdout替换成指定文件可以将数据输出到文件中。
下面举个例子:
#include<stdio.h>
int main(){
freopen("in.txt","r",stdin); //从in.txt中读数据
freopen("out.txt","w",stdout);//向out.txt中写数据
int a,b;
while(~scanf("%d%d", &a, &b)){
printf("%d %d\n");
}
return 0;
}
⑦ c语言中怎么在屏幕上输入文件名然后从此文件中读取内容到屏幕
#include<stdio.h>#include<string.h>voidmain(){intn;doublex,y,z;/*如果需要保存每次数据,可以用数组*/FILE*fp;charfilename[100];charstr[1000];printf(" Enterafilepath/filename: ");gets(filename);fp=fopen(filename,"rt");if(fp==NULL){printf("cannotopenfile ");return;}while(fgets(str,1000,fp))//读取一行,并判断文件是否结束{sscanf(str,"%d,%lf,%lf,%lf ",&n,&x,&y,&z);printf("%d,%e,%e,%e ",n,x,y,z);}fclose(fp);}
⑧ C语言习题 编写一程序 在屏幕上显示一菜单 并根据用户的选择执行相应的功能
#include"stdio.h"
intmain()
{
do{
intnum;
printf("主菜单项: 1-预览添加 2-查找修改 3-删除 0-退出系统 ");
printf("请选择操作:");
scanf("%d",&num);
switch(m)
{
case1:
printf("***信息预览添加*** ");
break;
case2:
printf("***信息查找修改*** ");
break;
case3:
printf("***信息删除*** ");
break;
case0:
printf("***退出系统*** ");
exit(0);
default:
break;
}}while(num!=0);
return0;
}
⑨ 用C语言如何将屏幕上所显示的内容全部保存到文件中
写个简单程序,基本写明了整体的流程,不明的函数网络就好了。
#include <sys\stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
int handle;
FILE *stream;
/* open a file */
handle = open("DUMMY.txt", O_CREAT,
S_IREAD | S_IWRITE);
/* now turn the handle into a stream */
stream = fdopen(handle, "w");
if (stream == NULL)
printf("fdopen failed\n");
else
{
fprintf(stream, "Hello world\n");
fclose(stream);
}
return 0;
}
复制不了????
关键是那几个函数,打开文件函数,录入函数,关闭函数,这些都是能网络到的,我只是给你举个程序,让你知道是怎么一个过程。真正理解还要靠你自己努力。
⑩ C语言怎么把刚在屏幕上输入的数据马上显示出来
话不多说,直接写代码,按照你说的我理解为:输入没有限制的字符数,输入完了用屏幕显示出来,每一个字符中间都要有一个空格作为间隔,对吗?,代码如下:
#include<stdio.h>
void
main()
{
int
x,y=0;
char
*a="123456";//在这个“”里面存放你想输出的字符,就可以了,接下来用for输出。
for(x=0;a[y]!=0;x++)
{
printf("%c
",a[y]);
y++;
}
getchar();
}