| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1775 人关注过本帖
标题:新手刚刚学习,望各位大哥多多指点!
只看楼主 加入收藏
isonation
Rank: 1
等 级:新手上路
帖 子:2
专家分:2
注 册:2012-1-2
收藏
得分:0 
e,刚刚改了一下,对于多少位(小于9),都能输出了,。
e,原来是c语言论坛,不过没关系,思路是一样的,。
2012-01-03 21:15
SHUJUNJIECR
Rank: 1
等 级:新手上路
帖 子:32
专家分:4
注 册:2011-11-3
收藏
得分:2 
学习了
2012-01-03 22:42
吴小君
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:102
专家分:198
注 册:2012-1-2
收藏
得分:0 
回复 29楼 liao06550107
我用turb2.0运行不起来啊
我自己写了一个
#include<stdio.h>
void main()
{
   char numchar[5][39]={{'o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ','o',' ','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o'},
{'o',' ','o',' ',' ',' ','o',' ',' ',' ','o',' ',' ',' ','o',' ','o',' ','o',' ','o',' ',' ',' ','o',' ',' ',' ',' ',' ','o',' ','o',' ','o',' ','o',' ','o'},
{'o',' ','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o'},
{'o',' ','o',' ',' ',' ','o',' ','o',' ',' ',' ',' ',' ','o',' ',' ',' ','o',' ',' ',' ','o',' ','o',' ','o',' ',' ',' ','o',' ','o',' ','o',' ',' ',' ','o'},
{'o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o'}};
    int num[5];
    int a,b=0,c,d,e=0,i=0,n=0;
    scanf("%d",&a);
    do
    {
    d=a-pow(10,e);
    e++;
    }
    while(d>=0);
    c=e-2;                                         //e-1是数的位数
   while(c>=0)
   {
    num[b]=a/pow(10,c);                            //num[b]是每位的数字
    a=a-num[b]*pow(10,c);
    c--;
    b++;
   }                                               //把给位数字存到num[0]-num[c]中
   while(i<5)                                      //numchar[i][]从0到4循环
   {
      while(n<=(e-2))                                //为了循环num[n]从0到e-2
      {
        switch(num[n])
        {
        case 0: printf("%c%c%c%c",numchar[i][0],numchar[i][1],numchar[i][2],numchar[i][3]);break;
        case 1: printf("%c%c%c%c",numchar[i][4],numchar[i][5],numchar[i][6],numchar[i][7]);break;
        case 2: printf("%c%c%c%c",numchar[i][8],numchar[i][9],numchar[i][10],numchar[i][11]);break;
        case 3: printf("%c%c%c%c",numchar[i][12],numchar[i][13],numchar[i][14],numchar[i][15]);break;
        case 4: printf("%c%c%c%c",numchar[i][16],numchar[i][17],numchar[i][18],numchar[i][19]);break;
        case 5: printf("%c%c%c%c",numchar[i][20],numchar[i][21],numchar[i][22],numchar[i][23]);break;
        case 6: printf("%c%c%c%c",numchar[i][24],numchar[i][25],numchar[i][26],numchar[i][27]);break;
        case 7: printf("%c%c%c%c",numchar[i][28],numchar[i][29],numchar[i][30],numchar[i][31]);break;
        case 8: printf("%c%c%c%c",numchar[i][32],numchar[i][33],numchar[i][34],numchar[i][35]);break;
        case 9: printf("%c%c%c%c",numchar[i][36],numchar[i][37],numchar[i][38]);break;
        }
       n++;
      }
     printf("\n");
    i++;
    }
}
如果改成单个的(如下)可以运行,但上面想运行多个数字的就不行了,就不知出了什么问题,求解
#include<stdio.h>
void main()
{
   char numchar[5][39]={{'o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ','o',' ','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o'},
{'o',' ','o',' ',' ',' ','o',' ',' ',' ','o',' ',' ',' ','o',' ','o',' ','o',' ','o',' ',' ',' ','o',' ',' ',' ',' ',' ','o',' ','o',' ','o',' ','o',' ','o'},
{'o',' ','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ','o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o'},
{'o',' ','o',' ',' ',' ','o',' ','o',' ',' ',' ',' ',' ','o',' ',' ',' ','o',' ',' ',' ','o',' ','o',' ','o',' ',' ',' ','o',' ','o',' ','o',' ',' ',' ','o'},
{'o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o',' ',' ',' ','o',' ','o','o','o',' ','o','o','o'}};
    int num[1]={3};
    int a,i=0;
    scanf("%d",&a);                                                  
   while(i<5)                                    
   {

        switch(num[0])
        {
        case 0: printf("%c%c%c%c",numchar[i][0],numchar[i][1],numchar[i][2],numchar[i][3]);break;
        case 1: printf("%c%c%c%c",numchar[i][4],numchar[i][5],numchar[i][6],numchar[i][7]);break;
        case 2: printf("%c%c%c%c",numchar[i][8],numchar[i][9],numchar[i][10],numchar[i][11]);break;
        case 3: printf("%c%c%c%c",numchar[i][12],numchar[i][13],numchar[i][14],numchar[i][15]);break;
        case 4: printf("%c%c%c%c",numchar[i][16],numchar[i][17],numchar[i][18],numchar[i][19]);break;
        case 5: printf("%c%c%c%c",numchar[i][20],numchar[i][21],numchar[i][22],numchar[i][23]);break;
        case 6: printf("%c%c%c%c",numchar[i][24],numchar[i][25],numchar[i][26],numchar[i][27]);break;
        case 7: printf("%c%c%c%c",numchar[i][28],numchar[i][29],numchar[i][30],numchar[i][31]);break;
        case 8: printf("%c%c%c%c",numchar[i][32],numchar[i][33],numchar[i][34],numchar[i][35]);break;
        case 9: printf("%c%c%c%c",numchar[i][36],numchar[i][37],numchar[i][38]);break;
        }
      
     printf("\n");
    i++;
    }
}

小弟学习C语言刚入门,请大侠们多多指教,不吝赐解!
2012-01-03 22:47
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
你们实践过后,再回头看我6楼所说,才能明白那是什么意思。没做之前,其实说了也不明白的。

授人以渔,不授人以鱼。
2012-01-04 04:55
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
以下是8楼的源代码,注意如下几点:
1.仔细观察ShowDigit()函数的实现,它输出的都是一个空格(L' '是空格字符),换言之,改成圈圈就是你所要的。不用理会那些SetTextAttribute()设置,你们用不着。
2.MoveCursor()函数是把光标定位到指定坐标处,只要把坐标(x,y)改为二维数组的下标,就是你们一直无法实现的东西。
3.定义一个足够大的二维char数组,逐点描图,完毕之后整个数组输出到控制台,就是结果。
4.控制台无法自由定位,但内存能够,在内存中做好一切准备工作然后集中呈现出来,是一个很重要的编程思路,现实中经常会遇到。

程序代码:
// 系统时间测试程序

#include <Windows.h>
#include <conio.h>
#include <Screen.h>

// 全局变量
Screen screen;

// 函数声明
VOID ShowDigit(const WCHAR digit, COORD location);

// 程序主入口
VOID wmain(VOID)
{
    screen.SetTitle(L"系统时间测试程序");
    screen.SetTextAttribute(FOREGROUND_WHITE | BACKGROUND_BLUE).Cls();
    screen.SetCursorVisible(false);

    screen.MoveCursor(0, screen.GetRows() - 1).WriteText(L"====按Esc键停止====");
    while (!(_kbhit() && (screen.ReadKey() == screen.K_ESC)))
    {
        static WORD second(-1);
        SYSTEMTIME st;
        GetLocalTime(&st);
        if (st.wSecond != second)
        {
            COORD location = {5, 2};
            WCHAR buffer[50];
            swprintf_s(buffer, L"%4d-%02d-%02d  %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
            for (size_t i = 0; i < wcslen(buffer); ++i)
            {
                ShowDigit(buffer[i], location);
                location.X += 3;
            }
            second = st.wSecond;
        }
    }

    screen.SetCursorVisible(true);
}

// 显示LED数字
VOID ShowDigit(const WCHAR digit, COORD location)
{
    const WORD attr(screen.GetTextAttribute());
    const WCHAR character = L' ';

    switch (digit)
    {
    case '-':
        screen.MoveCursor(location).SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case ':':
        screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·');
        ++location.Y;
        screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·');
        break;
    case '0':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '1':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        screen.SetTextAttribute(attr).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        screen.SetTextAttribute(attr).WriteText(character);
        break;
    case '2':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '3':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        break;
    case '4':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        break;
    case '5':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '6':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '7':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        break;
    case '8':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '9':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    }

    screen.SetTextAttribute(attr);
}

授人以渔,不授人以鱼。
2012-01-04 05:10
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:2 
融会贯通,神马都是浮云。试试下面这段代码。
程序代码:
#include<stdio.h>
void print(int a)
{
    const int map[10] = {
        0x75557, 0x44444, 0x71747, 0x74747, 0x44755,
        0x74717, 0x75717, 0x44447, 0x75757, 0x74757};
    int i, j, k, len, t;
    for(len = t = 0; a; len++, t *= 10, t += a % 10, a /= 10);
    if(!len) len = 1;
    a = t;
    for(i = 0; i < 5; i++, putchar('\n'))
    for(t = a, k = len; k--; t /= 10)
    for(j = 0; j < 4; putchar((((map[t % 10] >> (i * 4)) >> j++) & 1) ? 'O' : ' '));
}
int main()
{
    int a;
    scanf("%d", &a);
    print(a);
    return 0;
}

重剑无锋,大巧不工
2012-01-04 09:27
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
回复 35楼 TonyDeng
d:\c语言教程\c工程集\c论坛实例\光标定位001.c(6) : fatal error C1083: Cannot open include file: 'Screen.h': No such file or directory
是不是要去下个'screen.h'?

梅尚程荀
马谭杨奚







                                                       
2012-01-04 10:14
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
回复 37楼 有容就大
你无法执行的,我确实没有给出screen.h的源代码,贴那个只是给提示的。

授人以渔,不授人以鱼。
2012-01-04 12:18
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
回复 38楼 TonyDeng
能告诉我怎么定位光标吗?帮我看下26楼那个帖子怎么弄?

梅尚程荀
马谭杨奚







                                                       
2012-01-04 12:40
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
在控制台上,如果用printf()之类的输出函数,是无法使光标往回走的,这是一切基于流文件模式的本质特性。要使光标在控制台上往回走,必须调用系统功能,在Windows上,使用API函数(那就是被我用screen封装过的)。TC系列有gotoxy()函数,MS的随编译器版本不同而不同,在Windows环境下的MS编译器,都改成调用API了。注意:这些都不是标准C语言提供的东西。要坚持使用printf()系列的流模型,只能使用数组模拟屏幕——这是打印机打印图像的基本原理,因为打印头也同样是无法往回走的。

授人以渔,不授人以鱼。
2012-01-04 12:49
快速回复:新手刚刚学习,望各位大哥多多指点!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021147 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved