當前位置:首頁 » 編程語言 » c語言編寫控制台應用程序
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言編寫控制台應用程序

發布時間: 2022-09-10 19:41:49

㈠ 如何用c語言編寫控制台小游戲

//C語言實例:推箱子小游戲
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
//行和列
#defineROW10
#defineCOL11
/*,system("pause")orinputloop*/
/**
*

*
*/
//地圖
charmap[ROW][COL]={
"##########",//0
"#####",//1
"#####",//2
"##AX###",//3
"#####",//4
"######",//5
"###",//6
"#####",//7
"###",//8
"##########"//9
//A:人,X:箱子
};
//列印地圖
voidshowMap();
//接收小人的方向
charenterDirection();

//小人向上移動的方法
voidmoveToUp();
//小人向下移動的方法
voidmoveToDown();
//小人向右移動的方法
voidmoveToRight();
//小人向左移動的方法
voidmoveToLeft();

//當前小人的坐標
intcurrentPersonRow=3;
intcurrentPersonCol=2;
//當前箱子的坐標
intcurrentBoxRow=3;
intcurrentBoxCol=3;intmain(intargc,char*argv[]){
//system("clear");
printf("點擊回車鍵開始游戲^_^ ");
//1代表運行0停止
intflag=1;
while(flag==1){
//顯示地圖
showMap();
//接收小人的方向
chardir=enterDirection();
switch(dir){
//小人向上移動
case'w':
case'W':
moveToUp();
break;

//小人向下移動
case's':
case'S':
moveToDown();
break;
//小人向右移動
case'd':
case'D':
moveToRight();
break;
//小人向左移動
case'a':
case'A':
moveToLeft();
break;
//停止運行
case'q':
case'Q':
printf("你的智商真低!T_T ");
flag=0;
break;
}
showMap();
if(currentBoxRow==8&&currentBoxCol==9){
printf("你的智商真高^_^!!!");
flag=0;
}

}

}
/*
方法的實現
*/


//列印地圖
voidshowMap(){
inti;
for(i=0;i<ROW;i++){
printf("%s ",map[i]);
}
printf(" ");
printf("W:上,S:下,A:左,D:右。Q:退出");
printf(" ");
}
//接收小人的方向
charenterDirection(){
//清除SCANF中的緩沖區
rewind(stdin);
chardir;
dir=getch();
//scanf("%c",&dir);
returndir;
}
//小人向上移動的方法
voidmoveToUp(){
//小人的下一個坐標
intnextPersonCol=currentPersonCol;
intnextPersonRow=currentPersonRow-1;
//箱子的下一個坐標
intnextBoxRow=currentBoxRow-1;
intnextBoxCol=currentBoxCol;

//如果小人的下一個坐標是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一個坐標是牆
if(map[nextPersonRow][nextPersonCol]=='#'){
//什麼也不做
}
//如果小人的下一個坐標是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){

map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';


currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向下移動的方法
voidmoveToDown(){
//小人的下一個坐標
intnextPersonCol=currentPersonCol;
intnextPersonRow=currentPersonRow+1;
//箱子的下一個坐標
intnextBoxRow=currentBoxRow+1;
intnextBoxCol=currentBoxCol;

//如果小人的下一個坐標是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一個坐標是牆
if(map[nextPersonRow][nextPersonCol]=='#'){
//什麼也不做
}
//如果小人的下一個坐標是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){

map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';

currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向右移動的方法
voidmoveToRight(){
//小人的下一個坐標
intnextPersonCol=currentPersonCol+1;
intnextPersonRow=currentPersonRow;
//箱子的下一個坐標
intnextBoxRow=currentBoxRow;
intnextBoxCol=currentBoxCol+1;

//如果小人的下一個坐標是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一個坐標是牆
if(map[nextPersonRow][nextPersonCol]=='#'){
//什麼也不做
}
//如果小人的下一個坐標是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){

map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';

currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向左移動的方法
voidmoveToLeft(){
//小人的下一個坐標
intnextPersonCol=currentPersonCol-1;
intnextPersonRow=currentPersonRow;
//箱子的下一個坐標
intnextBoxRow=currentBoxRow;
intnextBoxCol=currentBoxCol-1;

//如果小人的下一個坐標是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一個坐標是牆
if(map[nextPersonRow][nextPersonCol]=='#'){
//什麼也不做
}
//如果小人的下一個坐標是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';

currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}

㈡ C語言編程題,編寫一控制台應用程序

#include<stdio.h>
void main() { int x;
scanf("%d",&x);
if ( x>=90 ) printf("優秀。\n");
else if ( x>=80 ) printf("良好。\n");
else if ( x>=70 ) printf("中等。\n");
else if ( x>=60 ) printf("合格。\n");
else printf("不合格。\n");

}

㈢ C語言怎麼只能編寫控制台應用程序,怎麼編寫WINDOWS 應用程序

需要些SDK的知識,windows的實現中基本上都是用的C語言,其各種介面基本上都是原生C語言函數,具體比如SDK用的windows API。
使用純C語言編寫windows程序,工作量將會相當大,下面是一個小例子:
/*
* This is a simple windows program, it does nothing but draw an ellipse.
* Windows SDK, Win32 API ,Pure C, (Not C++ or MFC !!)
* Suxpert at gmail dot com, 2008/8/24
* */
#include <windows.h>
LONG WINAPI WndProc( HWND, UINT, WPARAM, LPARAM );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow ){
/* The Entry for windows program, just like main() in dos */
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.style = 0; // Class style
wc.lpfnWndProc = (WNDPROC)WndProc; // Window procere address
wc.cbClsExtra = 0; // Class extra bytes
wc.cbWndExtra = 0; // Window extra bytes
wc.hInstance = hInstance; // Instance handle
wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Icon handle
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Cursor handle
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 ); // Background color
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = "WinSDKtest"; // WNDCLASS name
RegisterClass( &wc );
hwnd = CreateWindow (
"WinSDKtest", // WNDCLASS name
"SDK Application", // Window title
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, // Horizontal position
CW_USEDEFAULT, // Vertical position
CW_USEDEFAULT, // Initial width
CW_USEDEFAULT, // Initial height
HWND_DESKTOP, // Handle of parent window
NULL, // Menu handle
hInstance, // Application's instance handle
NULL // Window-creation data
);
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
while ( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
/* Windows will call this function anytime... */
PAINTSTRUCT ps;
HDC hdc;
switch(message){
case WM_PAINT:
hdc = BeginPaint( hwnd, &ps );
Ellipse( hdc, 0, 0, 800, 600 );
// Here we Draw an ellipse in the window of our program
EndPaint( hwnd, &ps );
break; // Someone like to write return here.
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
基本過程就是直接調用windows提供的API函數,完成從窗口創建,顯示等界面功能到深層的文件操作,注冊表等甚至windows內核調試等高級功能。

㈣ 編寫一個控制台應用程序,完成下列功能,並寫出運行程序後輸出的結果.

樓主你好。:

下是你想要的內容,

class Program
{
static void Main(string[] args)
{
ClassA classA = new ClassA();
Console.WriteLine("調用ClassA中方法返回的結果" + classA.MyMethod(100).ToString());
ClassB classB = new ClassB();
Console.WriteLine("調用ClassB中方法返回的結果" + classB.MyMethod(100).ToString());
Console.ReadLine();
}
}

class ClassA
{
public virtual int MyMethod(int inputNum)
{
int sumNum = inputNum + 10;
return sumNum;
}
}

class ClassB : ClassA
{
public override int MyMethod(int inputNum)
{
int sumNum = inputNum + 50;
return sumNum;
}
}

運行結果:

希望對有幫助,望採納,謝謝

㈤ C語言,指針數組問題,定義控制台應用程序的入口點的程序

4. fillcircle(p[i]->X, p[i]->Y, 10);
5那裡寫錯了,應該是delete p[i];

㈥ 用vc++創建控制台應用程序的步驟

1、首先打開桌面上本地已經安裝的VS2017開發工具IDE,如下圖所示。

㈦ C語言編寫的怎麼都是命令控制台程序

1、控制台程序是基礎,有基礎了寫圖形界面的程序就很簡單了。學完C++了學windows編程、MFC什麼的,到時候就是圖形界面了。


2、圖形界面需要些SDK的知識,windows的實現中基本上都是用的C語言,其各種介面基本上都是原生C語言函數,具體比如SDK用的windows API。
使用純C語言編寫windows程序,工作量將會相當大,下面是一個小例子:

/*
*Thisisasimplewindowsprogram,itdoesnothingbutdrawanellipse.
*WindowsSDK,Win32API,PureC,(NotC++orMFC!!)
*Suxpertatgmaildotcom,2008/8/24
**/
#include<windows.h>
LONGWINAPIWndProc(HWND,UINT,WPARAM,LPARAM);
intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,
LPSTRlpszCmdLine,intnCmdShow){
/*TheEntryforwindowsprogram,justlikemain()indos*/
WNDCLASSwc;
HWNDhwnd;
MSGmsg;
wc.style=0;//Classstyle
wc.lpfnWndProc=(WNDPROC)WndProc;//Windowprocereaddress
wc.cbClsExtra=0;//Classextrabytes
wc.cbWndExtra=0;//Windowextrabytes
wc.hInstance=hInstance;//Instancehandle
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);//Iconhandle
wc.hCursor=LoadCursor(NULL,IDC_ARROW);//Cursorhandle
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);//Backgroundcolor
wc.lpszMenuName=NULL;//Menuname
wc.lpszClassName="WinSDKtest";//WNDCLASSname
RegisterClass(&wc);
hwnd=CreateWindow(
"WinSDKtest",//WNDCLASSname
"SDKApplication",//Windowtitle
WS_OVERLAPPEDWINDOW,//Windowstyle
CW_USEDEFAULT,//Horizontalposition
CW_USEDEFAULT,//Verticalposition
CW_USEDEFAULT,//Initialwidth
CW_USEDEFAULT,//Initialheight
HWND_DESKTOP,//Handleofparentwindow
NULL,//Menuhandle
hInstance,//Application'sinstancehandle
NULL//Window-creationdata
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
returnmsg.wParam;
}
LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,
LPARAMlParam)
{
/*...*/
PAINTSTRUCTps;
HDChdc;
switch(message){
caseWM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Ellipse(hdc,0,0,800,600);
//
EndPaint(hwnd,&ps);
break;//Someoneliketowritereturnhere.
caseWM_DESTROY:
PostQuitMessage(0);
break;
default:
returnDefWindowProc(hwnd,message,wParam,lParam);
}
return0;
}


基本過程就是直接調用windows提供的API函數,完成從窗口創建,顯示等界面功能到深層的文件操作,注冊表等甚至windows內核調試等高級功能。

㈧ 請用c語言控制台程序寫一個程序

#include<stdio.h>

typedefstructpoint{
intx;
inty;
}quadrangle;

intmain(intargc,charconst*argv[])
{
quadranglefour[4];
inti,j,tmpx,tmpy;
for(i=0;i<4;i++)
{
printf("輸入第%d個點,每個點由x軸,y軸坐標表示如:125 ",i+1);
scanf("%d%d",&four[i].x,&four[i].y);
}
for(i=0;i<4;i++)
{
tmpx=four[i].x;
tmpy=four[i].y;
for(j=i+1;j<4;j++)
{
if(four[j].x<tmpx)
{
four[i].x=four[j].x;
four[i].y=four[j].y;
four[j].x=tmpx;
four[j].y=tmpy;
tmpx=four[i].x;
tmpy=four[i].y;
}
}
}
inta[2],b[2],c[2],d[2];
if(four[0].y>four[1].y)
{
a[0]=four[1].x;
a[1]=four[1].y;
d[0]=four[0].x;
d[1]=four[0].y;
}
else{
a[0]=four[0].x;
a[1]=four[0].y;
d[0]=four[1].x;
d[1]=four[1].y;
}
if(four[2].y>four[3].y)
{
b[0]=four[3].x;
b[1]=four[3].y;
c[0]=four[2].x;
c[1]=four[2].y;
}
else
{
b[0]=four[2].x;
b[1]=four[2].y;
c[0]=four[3].x;
c[1]=four[3].y;
}
printf("a(%d,%d)b(%d,%d)c(%d,%d)d(%d,%d) ",
a[0],a[1],b[0],b[1],c[0],c[1],d[0],d[1]);
return0;
}

㈨ C語言 控制台程序

不想調用控制台入口換winmain
底層的編譯,在編譯成目標文件之後,不要鏈接成可執行文件,生成別的
二進制文件
或者。。像
Linux內核
一樣,編譯成可執行文件,裝載入內存,然後用內存鏡像拷貝出純二進制文件。。等等方法
至於編譯驅動有另外更加專業的方法咯。。

㈩ c語言試題求解 3. 編寫一個控制台應用程序,輸出1到6的平方值,要求: 1) 用for語句

#include<stdio.h>
void main()
{
int i,m;
for(i=1;i<=6;i++)
{
m=i*i;
printf("%d的平方值=%d\n",i,m);
}
}

運行過了 沒有錯誤,望採納!