c語言函數---M




書畫小說軟件 制作更滿意的讀、更舒心的寫、更輕松的公布

最全古典小說網 由本軟件公布所得







                      main()主函數 每一C 程序都必須有一main()函數, 能夠依據自己的愛好把它放在程序的某 

個地方。有些程序猿把它放在最前面, 而還有一些程序猿把它放在最后面, 不管放

在哪個地方, 下面幾點說明都是適合的。

    1. main() 參數 在Turbo C2.0啟動過程中, 傳遞main()函數三個參數: argc, argvenv

* argc: 整數, 為傳給main()的命令行參數個數。

* argv: 字符串數組。 在DOS 3.X 版本號中, argv[0] 為程序運行的全路徑名; 對DOS 3.0 下面的版本號, argv[0]為空串("") 。

argv[1] 為在DOS命令行中運行程序名后的第一個字符串; argv[2] 為運行程序名后的第二個字符串; ... argv[argc]為NULL。 *env: 安符串數組。

env[] 的每個元素都包括ENVVAR=value形式的字符

串。

當中ENVVAR為環境變量如PATH或87。value 為ENVVAR的相應值如C:\DOS, C:

\TURBOC(對于PATH) 或YES(對于87)

Turbo C2.0啟動時總是把這三個參數傳遞給main()函數, 能夠在用戶程序中

說明(或不說明)它們, 假設說明了部分(或所有)參數, 它們就成為main()子程序

的局部變量。

    請注意: 一旦想說明這些參數, 則必須按argc, argv, env 的順序, 例如以下面 

的樣例:

     main() main(int argc) main(int argc, char *argv[]) main(int argc, char *argv[], char *env[]) 

當中另外一種情況是合法的, 但不常見, 由于在程序中非常少有僅僅用argc, 而不

用argv[]的情況。

    下面提供一例子程序EXAMPLE.EXE,  演示怎樣在main()函數中使用三個參數: /*program name EXAMPLE.EXE*/ #include <stdio.h> #include <stdlib.h> main(int argc, char *argv[], char *env[]) { int i; printf("These are the %d  command- line  arguments passed  to main:\n\n", argc); for(i=0; i<=argc; i++) printf("argv[%d]:%s\n", i, argv[i]); printf("\nThe environment string(s)on this system are:\n\n"); for(i=0; env[i]!=NULL; i++) printf(" env[%d]:%s\n", i, env[i]); } 假設在DOS 提示符下, 按下面方式執行EXAMPLE.EXE: C:\example first_argument "argument with blanks"  3  4  "last  but 
one" stop! 注意: 能夠用雙引號括起內含空格的參數, 如本例中的:   "  argument 
with blanks"和"Last but one")。

結果是這種: The value of argc is 7 These are the 7 command-linearguments passed to main: argv[0]:C:\TURBO\EXAMPLE.EXE argv[1]:first_argument argv[2]:argument with blanks argv[3]:3 argv[4]:4 argv[5]:last but one argv[6]:stop! argv[7]:(NULL) The environment string(s) on this system are: env[0]: COMSPEC=C:\COMMAND.COM env[1]: PROMPT=$P$G /*視詳細設置而定*/ env[2]: PATH=C:\DOS;C:\TC /*視詳細設置而定*/

應該提醒的是: 傳送main() 函數的命令行參數的最大長度為128 個字符 (包

括參數間的空格), 這是由DOS 限制的。

函數名: matherr

功 能: 用戶可改動的數學錯誤處理程序

用 法: int matherr(struct exception *e);

程序例:

/* This is a user-defined matherr function that prevents any error messages from being printed. */ 
#include<math.h> 
int matherr(struct exception *a) 
{ return 1; 
} 

函數名: memccpy

功 能: 從源source中拷貝n個字節到目標destin中

用 法: void *memccpy(void *destin, void *source, unsigned char ch,

       unsigned n); 

程序例:

#include <string.h> 
#include <stdio.h> 
int main(void) 
{ char *src = "This is the source string"; char dest[50]; char *ptr; ptr = memccpy(dest, src, 'c', strlen(src)); if (ptr) { *ptr = '\0'; printf("The character was found:  %s\n", dest); } else printf("The character wasn't found\n"); return 0; 
} 

函數名: malloc

功 能: 內存分配函數

用 法: void *malloc(unsigned size);

程序例:

#include <stdio.h> 
#include <string.h> 
#include <alloc.h> 
#include <process.h> 
int main(void) 
{ char *str; /* allocate memory for string */ /* This will generate an error when compiling */ /* with C++, use the new operator instead. */ if ((str = malloc(10)) == NULL) { printf("Not enough memory to allocate buffer\n"); exit(1);  /* terminate program if out of memory */ } /* copy "Hello" into string */ strcpy(str, "Hello"); /* display string */ printf("String is %s\n", str); /* free memory */ free(str); return 0; 
} 

函數名: memchr

功 能: 在數組的前n個字節中搜索字符

用 法: void *memchr(void *s, char ch, unsigned n);

程序例:

#include <string.h> 
#include <stdio.h> 
int main(void) 
{ char str[17]; char *ptr; strcpy(str, "This is a string"); ptr = memchr(str, 'r', strlen(str)); if (ptr) printf("The character 'r' is at position: %d\n", ptr - str); else printf("The character was not found\n"); return 0; 
} 

函數名: memcpy

功 能: 從源source中拷貝n個字節到目標destin中

用 法: void *memcpy(void *destin, void *source, unsigned n);

程序例:

#include <stdio.h> 
#include <string.h> 
int main(void) 
{ char src[] = "******************************"; char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709"; char *ptr; printf("destination before memcpy: %s\n", dest); ptr = memcpy(dest, src, strlen(src)); if (ptr) printf("destination after memcpy:  %s\n", dest); else printf("memcpy failed\n"); return 0; 
} 

函數名: memicmp

功 能: 比較兩個串s1和s2的前n個字節, 忽略大寫和小寫

用 法: int memicmp(void *s1, void *s2, unsigned n);

程序例:

#include <stdio.h> 
#include <string.h> 
int main(void) 
{ char *buf1 = "ABCDE123"; char *buf2 = "abcde456"; int stat; stat = memicmp(buf1, buf2, 5); printf("The strings to position 5 are "); if (stat) printf("not "); printf("the same\n"); return 0; 
} 

函數名: memmove

功 能: 移動一塊字節

用 法: void *memmove(void *destin, void *source, unsigned n);

程序例:

#include <string.h> 
#include <stdio.h> 
int main(void) 
{ char *dest = "abcdefghijklmnopqrstuvwxyz0123456789"; char *src = "******************************"; printf("destination prior to memmove: %s\n", dest); memmove(dest, src, 26); printf("destination after memmove:    %s\n", dest); return 0; 
} 

函數名: memset

功 能: 設置s中的全部字節為ch, s數組的大小由n給定

用 法: void *memset(void *s, char ch, unsigned n);

程序例:

#include <string.h> 
#include <stdio.h> 
#include <mem.h> 
int main(void) 
{ char buffer[] = "Hello world\n"; printf("Buffer before memset: %s\n", buffer); memset(buffer, '*', strlen(buffer) - 1); printf("Buffer after memset:  %s\n", buffer); return 0; 
} 

函數名: mkdir

功 能: 建立一個文件夾

用 法: int mkdir(char *pathname);

程序例:

#include <stdio.h> 
#include <conio.h> 
#include <process.h> 
#include <dir.h> 
int main(void) 
{ int status; clrscr(); status = mkdir("asdfjklm"); (!status) ? (printf("Directory created\n")) : (printf("Unable to create directory\n")); getch(); system("dir"); getch(); status = rmdir("asdfjklm"); (!status) ? (printf("Directory deleted\n")) : (perror("Unable to delete directory")); return 0; 
} 

函數名: mktemp

功 能: 建立唯一的文件名稱

用 法: char *mktemp(char *template);

程序例:

#include <dir.h> 
#include <stdio.h> 
int main(void) 
{ /* fname defines the template for the temporary file.  */ char *fname = "TXXXXXX", *ptr; ptr = mktemp(fname); printf("%s\n",ptr); return 0; 
} 

函數名: MK_FP

功 能: 設置一個遠指針

用 法: void far *MK_FP(unsigned seg, unsigned off);

程序例:

#include <dos.h> 
#include <graphics.h> 
int main(void) 
{ int gd, gm, i; unsigned int far *screen; detectgraph(&gd, &gm); if (gd == HERCMONO) screen = MK_FP(0xB000, 0); else screen = MK_FP(0xB800, 0); for (i=0; i<26; i++) screen[i] = 0x0700 + ('a' + i); return 0; 
} 

函數名: modf

功 能: 把數分為指數和尾數

用 法: double modf(double value, double *iptr);

程序例:

#include <math.h> 
#include <stdio.h> 
int main(void) 
{ double fraction, integer; double number = 100000.567; fraction = modf(number, &integer); printf("The whole and fractional parts of %lf are %lf and %lf\n", number, integer, fraction); return 0; 
} 

函數名: movedata

功 能: 拷貝字節

用 法: void movedata(int segsrc, int offsrc, int segdest,

  int offdest, unsigned numbytes); 

程序例:

#include <mem.h> 
#define MONO_BASE 0xB000 
/* saves the contents of the monochrome screen in buffer */ 
void save_mono_screen(char near *buffer) 
{ movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2); 
} 
int main(void) 
{ char buf[80*25*2]; save_mono_screen(buf); 
} 

函數名: moverel

功 能: 將當前位置(CP)移動一相對距離

用 法: void far moverel(int dx, int dy);

程序例:

#include <graphics.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 
int main(void) 
{ /* request auto detection */ int gdriver = DETECT, gmode, errorcode; char msg[80]; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk)  /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } /* move the C.P. to location (20, 30) */ moveto(20, 30); /* plot a pixel at the C.P. */ putpixel(getx(), gety(), getmaxcolor()); /* create and output a message at (20, 30) */ sprintf(msg, " (%d, %d)", getx(), gety()); outtextxy(20, 30, msg); /* move to a point a relative distance */ /* away from the current value of C.P. */ moverel(100, 100); /* plot a pixel at the C.P. */ putpixel(getx(), gety(), getmaxcolor()); /* create and output a message at C.P. */ sprintf(msg, " (%d, %d)", getx(), gety()); outtext(msg); /* clean up */ getch(); closegraph(); return 0; 
} 

函數名: movetext

功 能: 將屏幕文本從一個矩形區域復制到還有一個矩形區域

用 法: int movetext(int left, int top, int right, int bottom,

  int newleft, int newtop); 

程序例:

#include <conio.h> 
#include <string.h> 
int main(void) 
{ char *str = "This is a test string"; clrscr(); cputs(str); getch(); movetext(1, 1, strlen(str), 2, 10, 10); getch(); return 0; 
} 

函數名: moveto

功 能: 將CP移到(x, y)

用 法: void far moveto(int x, int y);

程序例:

#include <graphics.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 
int main(void) 
{ /* request auto detection */ int gdriver = DETECT, gmode, errorcode; char msg[80]; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk)  /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } /* move the C.P. to location (20, 30) */ moveto(20, 30); /* plot a pixel at the C.P. */ putpixel(getx(), gety(), getmaxcolor()); /* create and output a message at (20, 30) */ sprintf(msg, " (%d, %d)", getx(), gety()); outtextxy(20, 30, msg); /* move to (100, 100) */ moveto(100, 100); /* plot a pixel at the C.P. */ putpixel(getx(), gety(), getmaxcolor()); /* create and output a message at C.P. */ sprintf(msg, " (%d, %d)", getx(), gety()); outtext(msg); /* clean up */ getch(); closegraph(); return 0; 
} 

函數名: movemem

功 能: 移動一塊字節

用 法: void movemem(void *source, void *destin, unsigned len);

程序例:

#include <mem.h> 
#include <alloc.h> 
#include <stdio.h> 
#include <string.h> 
int main(void) 
{ char *source = "Borland International"; char *destination; int length; length = strlen(source); destination = malloc(length + 1); movmem(source,destination,length); printf("%s\n",destination); return 0; 
} 

函數名: normvideo

功 能: 選擇正常亮度字符

用 法: void normvideo(void);

程序例:

#include <conio.h> 
int main(void) 
{ normvideo(); cprintf("NORMAL Intensity Text\r\n"); return 0; 
} 

函數名: nosound

功 能: 關閉PC揚聲器

用 法: void nosound(void);

程序例:

/* Emits a 7-Hz tone for 10 seconds. True story: 7 Hz is the resonant frequency of a chicken's skull cavity. This was determined empirically in Australia, where a new factory generating 7-Hz tones was located too close to a chicken ranch: When the factory started up, all the chickens died. Your PC may not be able to emit a 7-Hz tone. 
*/ 
int main(void) 
{ sound(7); delay(10000); nosound(); 
} 



書畫小說軟件 制作更滿意的讀、更舒心的寫、更輕松的公布

最全古典小說網 由本軟件公布所得

轉載于:https://www.cnblogs.com/bhlsheji/p/5257960.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/373499.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/373499.shtml
英文地址,請注明出處:http://en.pswp.cn/news/373499.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

使用Apache ActiveMQ的JMS開發基礎

去年是我嘗試JMS的時候。 背后的想法和概念讓我有些困惑&#xff0c;但是當我知道它的用途后&#xff0c;我很快就掌握了它。 在本文中&#xff0c;我將展示使用Apache ActiveMQ作為后端使用Java開發簡單的生產者/消費者的基礎。 讓我們首先從概念開始&#xff0c;這是一個簡單…

vijos p1460——拉力賽

描述 車展結束后&#xff0c;游樂園決定舉辦一次盛大的山道拉力賽&#xff0c;平平和韻韻自然也要來參加大賽。 賽場上共有n個連通的計時點&#xff0c;n-1條賽道&#xff08;構成了一棵樹&#xff09;。每個計時點的高度都不相同&#xff08;父結點的高度必然大于子結點&#…

mysql acid_Mysql中ACID的原理

原子性 (Atomicity)原子性是指一個事務是一個不可分割的工作單位&#xff0c;其中的操作要么都做&#xff0c;要么都不做。隔離性 (Isolation)隔離性是指多個事務并發執行的時候&#xff0c;事務內部的操作與其他事務是隔離的&#xff0c;并發執行的各個事務之間不能互相干擾…

MongoDB 自動刪除集合中過期的數據——TTL索引

簡介 ? TTL (Time To Live, 有生命周期的) 索引是特殊單字段索引&#xff0c;MongoDB可以用來在一定時間后自動從集合中刪除文檔的特殊索引。 這對于某些類型的數據非常好&#xff0c;例如機器生成的事件數據&#xff0c;日志和會話信息&#xff0c;這些信息只需要在數據庫中…

PLSQL 經常自動斷開失去連接的解決過程

問題背景&#xff1a; 情況是這樣的&#xff0c;很多開發同事的PLSQL上班時間開著8個小時&#xff0c;有時候他們出去抽煙后或者中午吃完飯&#xff0c;回來在PLSQL上面執行就報錯無響應&#xff0c;然后卡住了半天動彈不了&#xff0c;非得重新登錄plsql才生效&#xff0c;我猜…

使用Cobertura,JUnit,HSQLDB,JPA涵蓋您的測試

你好&#xff01;你好嗎&#xff1f; 今天讓我們談談一個非常有用的工具&#xff0c;名為“ Cobertura”。 該框架與我們在另一篇文章中看到的Emma框架具有相同的功能。 Cobertura和Emma之間的主要區別在于Cobertura顯示帶有圖形的簡歷頁面。 如果要查看有關該主題的其他主題…

fedora mysql gui_fedora8安裝 mysql++失敗!!裝了一個晚上沒搞定!!傷心阿!

fedora8安裝 mysql失敗&#xff01;&#xff01;裝了一個晚上沒搞定&#xff01;&#xff01;傷心阿&#xff01;發布時間:2008-02-24 05:15:27來源:紅聯作者:lygzx[rootF8 mysql-3.0.0]# ./configure --w/usr/lib/mysqlconfigure: error: unrecognized option: --w/usr/lib/my…

MongoDB 數組類型查詢 —— $elemMatch 操作符

描述 $elemMatch 數組查詢操作用于查詢數組值中至少有一個能完全匹配所有的查詢條件的文檔。語法格式如下&#xff1a; { <field>: { $elemMatch: { <query1>, <query2>, ... } } }如果只有一個查詢條件就沒必要使用 $elemMatch。 限制 不能指定 $where 查…

MVC4 Action 方法的執行

1. ActionInvoker 的執行&#xff1a; 在MVC 中 包括Model綁定與驗證在內的整個Action的執行是通過一個名為ActionInvoker的組件來完成的。 它同樣具有 同步/異步兩個版本。 分別實現了接口 IActionInvoker /IAsyncActionInvoker。 ASP.NET MVC 中真正用于Action方法同步和異步…

C# 基礎知識總結

要學好C#&#xff0c;基礎知識的重要性不言而喻&#xff0c;現將常用到的一些基礎進行總結&#xff0c;總結如下&#xff1a; 01. 數據類型轉換&#xff1a; 強制類型轉換(Chart--> int): char crA; int i (int)(cr); 02. 委托/匿名函數/Lamda表達式&#xff1a; 委托是匿…

Java注釋和真實世界的Spring示例

“注釋”是編程語言定義的一種&#xff0c;用作“標記”。 可以將它們視為編程語言引擎可以理解的注釋行。 它們不會直接影響程序的執行&#xff0c;但是會在需要時間接影響。 定義 注釋使用interface關鍵字定義&#xff0c;并且與接口相似。 它具有定義類似于接口方法的屬性。…

scrapy+mysql+pipeline+更新數據_python3+Scrapy爬蟲實戰(二)—— 使用pipeline數據保存到文本和數據庫(mysql)...

前言保存本地存儲Json數據配置setting保存數據庫創建數據庫創建表編寫pipelines配置setting本文是對上篇文章所講的代碼進一步優化&#xff0c;回看可以點這里&#xff0c;代碼就直接在上一篇代碼中進行改造&#xff0c;沒有的小伙伴可以在這里下載。前言Scrapy 提供了 pipelin…

NYOJ 44 子串和

子串和 時間限制&#xff1a;5000 ms | 內存限制&#xff1a;65535 KB難度&#xff1a;3描述 給定一整型數列{a1,a2...,an}&#xff0c;找出連續非空子串{ax,ax1,...,ay}&#xff0c;使得該子序列的和最大&#xff0c;其中&#xff0c;1<x<y<n。 輸入 第一行是一個…

學習進度條

學習進度條 周次 學習時間 新編寫代碼行數 博客量&#xff08;篇&#xff09; 學到知識點 第一周 160 0 1 github的使用和認識軟件工程這門課的價值。 第二周 160 130 3 復利的計算和Github的一些簡單操作還有就是進行項目的開發分析&#xff0c;還有就是對…

ARM基礎

1.  將32位a的【7&#xff1a;4】改成0101 -> a a&(~(0xF << 4)) | (0x5 << 4)&#xff1b; 2.  32位&#xff1a;單次處理數據32位。 3.  對于CPU而言&#xff0c;一切皆內存&#xff1b; 4.  DMA總線&#xff1a;不經過CPU直接在內存和內存間交換…

使用Jolokia和JMX進行客戶端服務器監視

Java監視工具的選擇非常廣泛&#xff08;由Google提供的隨機選擇和順序&#xff09;&#xff1a; javamelody 壓力探頭 JVisualVM 控制臺 賈蒙 Java JMX Nagios插件不適用 此外&#xff0c;還有各種專用工具&#xff0c;例如ActiveMQ &#xff0c; JBoss &#xff0c; Qu…

圖書管理系統數據字典_2. 結構化——數據字典

返回目錄&#xff1a;Chilan Yuk&#xff1a;軟件工程分析設計圖庫目錄?zhuanlan.zhihu.com一、基本知識用于定義數據流和數據存儲的結構&#xff0c;并給出構成所給的數據流和數據存儲的各數據項的基本數據類型。數據字典中應該包括關于數據的如下信息一般信息&#xff08;名…

HDOJ 5184 Brackets 卡特蘭數擴展

既求從點(0,0)僅僅能向上或者向右而且不穿越yx到達點(a,b)有多少總走法... 有公式: C(ab,min(a,b))-C(ab,min(a,b)-1) /// 折紙法證明卡特蘭數: http://blog.sina.com.cn/s/blog_6917f47301010cno.html Brackets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65…

010-python基礎-數據類型-字符串操作

1、移除空白 1 username.strip() 2、分割 1 names "alex,jack,rain" 2 names_1 names.split(",") #  字符串分割之后變成列表 3 print(names_1) 4 #輸出 5 [alex, jack, rain] 3、合并列表各元素成為字符串 1 names_1 [alex, jack, rain]2 names_2…

重復次數最多的 子串_每日算法系列【LeetCode 424】替換后的最長重復字符

題目描述給你一個僅由大寫英文字母組成的字符串&#xff0c;你可以將任意位置上的字符替換成另外的字符&#xff0c;總共可最多替換 k 次。在執行上述操作后&#xff0c;找到包含重復字母的最長子串的長度。示例1輸入&#xff1a; s "ABAB", k 2 輸出&#xff1a; …