當前位置:首頁 » 編程語言 » c語言二維滑窗
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言二維滑窗

發布時間: 2022-06-11 12:19:47

c語言編寫可以運行顯示的簡單的二維圖形

用輸出函數printf() 可以畫出圖形 但是這種圖形都是一個一個的符號拼起來的,如果想顯示一個jpg圖片C語言好像有點難 C++就容易得多了

Ⅱ C語言 定義了二維字元組char a[M][N]. 要在運行窗口用戶自己輸入二維數組 每行的個數不確定 怎麼寫程序

如果行數確定了,那麼可以定義一維指針數組,然後再通過malloc或者calloc函數動態分配多個數組。在讀取用戶輸入的時候,如果發現數組長度不夠,還可以用calloc重新分配更長的空間

Ⅲ C語言「窗口滑動」代碼中的疑問

這個是在命令行中模擬圖形界面的操作?
n表示你設定的窗口大小, 也就是每行的字元數.

r表示送入和刪除字元後, 當前所在的窗口位置.

Ⅳ 怎麼用C語言做二維 三維 動畫 窗口的程序

我有相關的資料(原版英文書), 但無法傳遞給你!!! 給你個實常式序:(太長,程序沒發完)
/*
GRAPHICS DEMO FOR TURBO C 2.0

Copyright (c) 1987,88 Borland International. All rights reserved.

From the command line, use:

tcc bgidemo graphics.lib

*/

#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif

#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include <graphics.h>

#define ESC 0x1b /* Define the escape key */
#define TRUE 1 /* Define some handy constants */
#define FALSE 0 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define ON 1 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */

char *Fonts[] = {
"DefaultFont", "TriplexFont", "SmallFont",
"SansSerifFont", "GothicFont"
};

char *LineStyles[] = {
"SolidLn", "DottedLn", "CenterLn", "DashedLn", "UserBitLn"
};

char *FillStyles[] = {
"EmptyFill", "SolidFill", "LineFill", "LtSlashFill",
"SlashFill", "BkSlashFill", "LtBkSlashFill", "HatchFill",
"XHatchFill", "InterleaveFill", "WideDotFill", "CloseDotFill"
};

char *TextDirect[] = {
"HorizDir", "VertDir"
};

char *HorizJust[] = {
"LeftText", "CenterText", "RightText"
};

char *VertJust[] = {
"BottomText", "CenterText", "TopText"
};

struct PTS {
int x, y;
}; /* Structure to hold vertex points */

int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
double AspectRatio; /* Aspect ratio of a pixel on the screen*/
int MaxX, MaxY; /* The maximum resolution of the screen */
int MaxColors; /* The maximum # of colors available */
int ErrorCode; /* Reports any graphics errors */
struct palettetype palette; /* Used to read palette info */

/* */
/* Function prototypes */
/* */

void Initialize(void);
void ReportStatus(void);
void TextDump(void);
void Bar3DDemo(void);
void RandomBars(void);
void TextDemo(void);
void ColorDemo(void);
void ArcDemo(void);
void CircleDemo(void);
void PieDemo(void);
void BarDemo(void);
void LineRelDemo(void);
void PutPixelDemo(void);
void PutImageDemo(void);
void LineToDemo(void);
void LineStyleDemo(void);
void CRTModeDemo(void);
void UserLineStyleDemo(void);
void FillStyleDemo(void);
void FillPatternDemo(void);
void PaletteDemo(void);
void PolyDemo(void);
void SayGoodbye(void);
void Pause(void);
void MainWindow(char *header);
void StatusLine(char *msg);
void DrawBorder(void);
void changetextstyle(int font, int direction, int charsize);
int gprintf(int *xloc, int *yloc, char *fmt, ... );

/* */
/* Begin main function */
/* */

int main()
{

Initialize(); /* Set system into Graphics mode */
ReportStatus(); /* Report results of the initialization */

ColorDemo(); /* Begin actual demonstration */
if( GraphDriver==EGA || GraphDriver==EGALO || GraphDriver==VGA )
PaletteDemo();
PutPixelDemo();
PutImageDemo();
Bar3DDemo();
BarDemo();
RandomBars();
ArcDemo();
CircleDemo();
PieDemo();
LineRelDemo();
LineToDemo();
LineStyleDemo();
UserLineStyleDemo();
TextDump();
TextDemo();
CRTModeDemo();
FillStyleDemo();
FillPatternDemo();
PolyDemo();
SayGoodbye(); /* Give user the closing screen */

closegraph(); /* Return the system to text mode */
return(0);
}

/* */
/* INITIALIZE: Initializes the graphics system and reports */
/* any errors which occured. */
/* */

void Initialize(void)
{
int xasp, yasp; /* Used to read the aspect ratio*/

GraphDriver = DETECT; /* Request auto-detection */
initgraph( &GraphDriver, &GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk ){ /* Error occured ring init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}

getpalette( &palette ); /* Read the palette from board */
MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/

MaxX = getmaxx();
MaxY = getmaxy(); /* Read size of screen */

getaspectratio( &xasp, &yasp ); /* read the hardware aspect */
AspectRatio = (double)xasp / (double)yasp; /* Get correction factor */

}

/* */
/* REPORTSTATUS: Report the current configuration of the system */
/* after the auto-detect initialization. */
/* */

void ReportStatus(void)
{
struct viewporttype viewinfo; /* Params for inquiry proceres*/
struct linesettingstype lineinfo;
struct fillsettingstype fillinfo;
struct textsettingstype textinfo;
struct palettetype palette;

char *driver, *mode; /* Strings for driver and mode */
int x, y;

getviewsettings( &viewinfo );
getlinesettings( &lineinfo );
getfillsettings( &fillinfo );
gettextsettings( &textinfo );
getpalette( &palette );

x = 10;
y = 4;

MainWindow( "Status report after InitGraph" );
settextjustify( LEFT_TEXT, TOP_TEXT );

driver = getdrivername();
mode = getmodename(GraphMode); /* get current setting */

gprintf( &x, &y, "Graphics device : %-20s (%d)", driver, GraphDriver );
gprintf( &x, &y, "Graphics mode : %-20s (%d)", mode, GraphMode );
gprintf( &x, &y, "Screen resolution : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );

gprintf( &x, &y, "Current view port : ( %d, %d, %d, %d )",
viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
gprintf( &x, &y, "Clipping : %s", viewinfo.clip ? "ON" : "OFF" );

gprintf( &x, &y, "Current position : ( %d, %d )", getx(), gety() );
gprintf( &x, &y, "Colors available : %d", MaxColors );
gprintf( &x, &y, "Current color : %d", getcolor() );

gprintf( &x, &y, "Line style : %s", LineStyles[ lineinfo.linestyle ] );
gprintf( &x, &y, "Line thickness : %d", lineinfo.thickness );

gprintf( &x, &y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
gprintf( &x, &y, "Current fill color : %d", fillinfo.color );

gprintf( &x, &y, "Current font : %s", Fonts[ textinfo.font ] );
gprintf( &x, &y, "Text direction : %s", TextDirect[ textinfo.direction ] );
gprintf( &x, &y, "Character size : %d", textinfo.charsize );
gprintf( &x, &y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
gprintf( &x, &y, "Vertical justify : %s", VertJust[ textinfo.vert ] );

Pause(); /* Pause for user to read screen*/

}

/* */
/* TEXTDUMP: Display the all the characters in each of the */
/* available fonts. */
/* */

void TextDump()
{
static int CGASizes[] = {
1, 3, 7, 3, 3 };
static int NormSizes[] = {
1, 4, 7, 4, 4 };

char buffer[80];
int font, ch, wwidth, lwidth, size;
struct viewporttype vp;

for( font=0 ; font<5 ; ++font ){ /* For each available font */
sprintf( buffer, "%s Character Set", Fonts[font] );
MainWindow( buffer ); /* Display fontname as banner */
getviewsettings( &vp ); /* read current viewport */

settextjustify( LEFT_TEXT, TOP_TEXT );
moveto( 2, 3 );

buffer[1] = '\0'; /* Terminate string */
wwidth = vp.right - vp.left; /* Determine the window width */
lwidth = textwidth( "H" ); /* Get average letter width */

if( font == DEFAULT_FONT ){
changetextstyle( font, HORIZ_DIR, 1 );
ch = 0;
while( ch < 256 ){ /* For each possible character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (getx() + lwidth) > wwidth )
moveto( 2, gety() + textheight("H") + 3 );
++ch; /* Goto the next character */
}
}
else{

size = (MaxY < 200) ? CGASizes[font] : NormSizes[font];
changetextstyle( font, HORIZ_DIR, size );

ch = '!'; /* Begin at 1st printable */
while( ch < 127 ){ /* For each printable character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (lwidth+getx()) > wwidth ) /* Are we still in window? */
moveto( 2, gety()+textheight("H")+3 );
++ch; /* Goto the next character */
}

}

Pause(); /* Pause until user acks */

} /* End of FONT loop */

}

/* */
/* BAR3DDEMO: Display a 3-D bar chart on the screen. */
/* */

void Bar3DDemo(void)
{
static int barheight[] = {
1, 3, 5, 4, 3, 2, 1, 5, 4, 2, 3 };
struct viewporttype vp;
int xstep, ystep;
int i, j, h, color, bheight;
char buffer[10];

MainWindow( "Bar 3-D / Rectangle Demonstration" );

h = 3 * textheight( "H" );
getviewsettings( &vp );
settextjustify( CENTER_TEXT, TOP_TEXT );
changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
outtextxy( MaxX/2, 6, "These are 3-D Bars" );
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
setviewport( vp.left+50, vp.top+40, vp.right-50, vp.bottom-10, 1 );
getviewsettings( &vp );

line( h, h, h, vp.bottom-vp.top-h );
line( h, (vp.bottom-vp.top)-h, (vp.right-vp.left)-h, (vp.bottom-vp.top)-h );
xstep = ((vp.right-vp.left) - (2*h)) / 10;
ystep = ((vp.bottom-vp.top) - (2*h)) / 5;
j = (vp.bottom-vp.top) - h;
settextjustify( CENTER_TEXT, CENTER_TEXT );

for( i=0 ; i<6 ; ++i ){
line( h/2, j, h, j );
itoa( i, buffer, 10 );
outtextxy( 0, j, buffer );
j -= ystep;
}

j = h;
settextjustify( CENTER_TEXT, TOP_TEXT );

for( i=0 ; i<11 ; ++i ){
color = random( MaxColors );
setfillstyle( i+1, color );
line( j, (vp.bottom-vp.top)-h, j, (vp.bottom-vp.top-3)-(h/2) );
itoa( i, buffer, 10 );
outtextxy( j, (vp.bottom-vp.top)-(h/2), buffer );
if( i != 10 ){
bheight = (vp.bottom-vp.top) - h - 1;
bar3d( j, (vp.bottom-vp.top-h)-(barheight[i]*ystep), j+xstep, bheight, 15, 1 );
}
j += xstep;
}

Pause(); /* Pause for user's response */

}

/* */
/* RANDOMBARS: Display random bars */
/* */

void RandomBars(void)
{
int color;

MainWindow( "Random Bars" );
StatusLine( "Esc aborts or press a key..." ); /* Put msg at bottom of screen */
while( !kbhit() ){ /* Until user enters a key... */
color = random( MaxColors-1 )+1;
setcolor( color );
setfillstyle( random(11)+1, color );
bar3d( random( getmaxx() ), random( getmaxy() ),
random( getmaxx() ), random( getmaxy() ), 0, OFF);
}

Pause(); /* Pause for user's response */

}

/* */
/* TEXTDEMO: Show each font in several sizes to the user. */
/* */

void TextDemo(void)
{
int charsize[] = {
1, 3, 7, 3, 4 };
int font, size;
int h, x, y, i;
struct viewporttype vp;
char buffer[80];

for( font=0 ; font<5 ; ++font ){ /* For each of the four fonts */

sprintf( buffer, "%s Demonstration", Fonts[font] );
MainWindow( buffer );
getviewsettings( &vp );

changetextstyle( font, VERT_DIR, charsize[font] );
settextjustify( CENTER_TEXT, BOTTOM_TEXT );
outtextxy( 2*textwidth("M"), vp.bottom - 2*textheight("M"), "Vertical" );

changetextstyle( font, HORIZ_DIR, charsize[font] );
settextjustify( LEFT_TEXT, TOP_TEXT );
outtextxy( 2*textwidth("M"), 2, "Horizontal" );

settextjustify( CENTER_TEXT, CENTER_TEXT );
x = (vp.right - vp.left) / 2;
y = textheight( "H" );

for( i=1 ; i<5 ; ++i ){ /* For each of the sizes */
size = (font == SMALL_FONT) ? i+3 : i;
changetextstyle( font, HORIZ_DIR, size );
h = textheight( "H" );
y += h;
sprintf( buffer, "Size %d", size );
outtextxy( x, y, buffer );

}

if( font != DEFAULT_FONT ){ /* Show user declared font size */
y += h / 2; /* Move down the screen */
settextjustify( CENTER_TEXT, TOP_TEXT );
setusercharsize( 5, 6, 3, 2 );
changetextstyle( font, HORIZ_DIR, USER_CHAR_SIZE );
outtextxy( (vp.right-vp.left)/2, y, "User Defined Size" );
}

Pause(); /* Pause to let user look */

} /* End of FONT loop */

}

/* */
/* COLORDEMO: Display the current color palette on the screen. */
/* */

void ColorDemo(void)
{
struct viewporttype vp;
int color, height, width;
int x, y, i, j;
char cnum[5];

MainWindow( "Color Demonstration" ); /* Show demonstration name */

color = 1;
getviewsettings( &vp ); /* Get the current window size */
width = 2 * ( (vp.right+1) / 16 ); /* Get box dimensions */
height = 2 * ( (vp.bottom-10) / 10 );

x = width / 2;
y = height / 2; /* Leave 1/2 box border */

for( j=0 ; j<3 ; ++j ){ /* Row loop */

for( i=0 ; i<5 ; ++i ){ /* Column loop */

setfillstyle(SOLID_FILL, color); /* Set to solid fill in color */
setcolor( color ); /* Set the same border color */

bar( x, y, x+width, y+height ); /* Draw the rectangle */
rectangle( x, y, x+width, y+height ); /* outline the rectangle */

if( color == BLACK ){ /* If box was black... */
setcolor( WHITE ); /* Set drawing color to white */
rectangle( x, y, x+width, y+height ); /* Outline black in white*/
}

itoa( color, cnum, 10 ); /* Convert # to ASCII */
outtextxy( x+(width/2), y+height+4, cnum ); /* Show color # */

color = ++color % MaxColors; /* Advance to the next color */
x += (width / 2) * 3; /* move the column base */
} /* End of Column loop */

y += (height / 2) * 3; /* move the row base */
x = width / 2; /* reset column base */
} /* End of Row loop */

Pause(); /* Pause for user's response */

}

/* */
/* ARCDEMO: Display a random pattern of arcs on the screen */
/* until the user says enough. */
/* */

void ArcDemo(void)
{
int mradius; /* Maximum radius allowed */
int eangle; /* Random end angle of Arc */
struct arccoordstype ai; /* Used to read Arc Cord info */

MainWindow( "Arc Demonstration" );
StatusLine( "ESC Aborts - Press a Key to stop" );

mradius = MaxY / 10; /* Determine the maximum radius */

while( !kbhit() ){ /* Repeat until a key is hit */
setcolor( random( MaxColors - 1 ) + 1 ); /* Randomly select a color */
eangle = random( 358 ) + 1; /* Select an end angle */
arc( random(MaxX), random(MaxY), random(eangle), eangle, mradius );
getarccoords( &ai ); /* Read Cord data */
line( ai.x, ai.y, ai.xstart, ai.ystart ); /* line from start to center */
line( ai.x, ai.y, ai.xend, ai.yend ); /* line from end to center */
} /* End of WHILE not KBHIT */

Pause(); /* Wait for user's response */

}

Ⅳ c語言,怎麼把一個整形二維數組輸入exe窗口,去執行程序中對二維數組各項的運算。 在源程序中

你看c語言書沒,基本的輸入輸出和數組操作你不知道嗎

Ⅵ c語言二維數組問題

今日在論壇上看到有人問到指針的問題,我想通過這樣的例子來闡述幾個常見的錯誤,並加深對二
級指針和二維數組之間關系的理解.
我們知道char array[]=」abcdef」; array是數組的首地址,
那麼在二維數組中array當然也是數組的首地址,
看看這個定義char Array[][3] ={「ab「,「cd「,「ef「};
怎麼知道的呢?定義這樣一個數組,在vc調試窗口中
我們看到:
Array ---------0x64324234
|------Array[0]---0x64324234 「ab「
|------Array[1]---0x64324337 「cd「
|------Array[2]---0x6432433A 「ef」
已經很明白了,實際編譯器是這樣實現二維數組的,實際上Array是「一維指針數組「的首地址,其中每一個元素指針都
對應一個字元串,那麼好我們來看看是否可以這樣來使用Array二維數組.
char **pArray = Array;編譯器提示出錯,怎麼辦呢?加個(char **)試試,仍然出錯,設斷看一下pArray的值和Array
的值是相等的,但我們是否可以象使用Array[i]那樣來同樣輸出字元串呢?很明顯是不行的,編譯器不會把
pArray+i處理成pArray+i*3尋找到第i個指針的地址,而只是簡單的加了一個i.這說明編譯器只做了很簡單的將地址值賦給
了pArray,而它實際沒有任何意義.我們不能用它來訪問任何數據.很奇怪嗎?
再來看看這樣定義char *p[] = {「ab「, 「cd「, 「ef「};定義了一個指針數組.char **sp = p;這樣的用法經常看到,為什麼這樣
就可以使用sp[i]來訪問字元串了呢,的確編譯器在編譯的時候識別出了sp是一個指向一維數組的指針的
指針,那麼我們就可以把它做為數組名來操縱整個數組了,c神奇的地方或者說精華的地方就在這里了,希望
這篇文章對那些對指針或二級指針有疑惑的朋友能夠有所幫助,這也是我blog里的第一篇文章,呵呵.

Ⅶ C語言,動態分配內存(二維數組)輸入數據時為什麼會彈出對話框求網友指點

for(i=0;i<n;i++)

{for(j=0;j<n;j++)

改成:

for(i=1;i<n;i++)

{for(j=1;j<n;j++)

因為你根本沒有給i=0分配地址,所以出錯。

修改後的程序如下:

#include<stdio.h>
#include<stdlib.h>
intmain(void)
{
int**a,i,j;
intn;
scanf("%d",&n);
a=(int**)malloc((n+1)*sizeof(int*));
for(i=1;i<=n;i++)
a[i]=(int*)malloc((n+1)*sizeof(int));//分配內存的時候是
for(i=1;i<n;i++)
for(j=1;j<n;j++)
scanf("%d",&a[i][j]);
for(i=1;i<n;i++)
{for(j=1;j<n;j++)
printf("%d",a[i][j]);
printf(" ");}

}

已經運行過,有什麼問題請留言。

Ⅷ C語言 如何實現窗口的上下移動 左右移動

這個很復雜的 你要重新寫好多函數 包括像printf 什麼的
因為有可能讓他列印一個字元串,但是有很多字元是沒在屏幕裡面的
而系統是沒有這些方便的函數的

工作量太大,你估計不會去寫得

Ⅸ 誰能幫我做個c++或c語言編寫的實現滑動窗口協議的程序啊,要能運行的,給個cpp也行,很急。

請自己寫....

#include<stdio.h>
intmain()
{
return0;
}
開頭給你了,加油~

Ⅹ 怎樣在c語言中使用窗口

用windows API可以實現。如果想要深入學習的話,推薦你看一下《windows程序設計》這本書,這本書就是介紹如何用C語言編寫windows界面程序的。但這本書現在已經不出版了,可以下本電子檔看看。