c語言庫函數源代碼
Ⅰ 如何查看c語言,內庫的源代碼
如果是「.cpp」文件並且有VC++的環境,可直接雙擊文件打開或者先打開編譯環境,在新建一個控制台下的源文件,然後,選擇file菜單下的open找到你的文件導入,然後編譯運行;如果是其他格式的,如txt文件,也可先打開編譯環境,新建一個控制台下的源文件,然後直接復制粘貼進去,然後編譯運行;
便已運行的操作如圖:
Ⅱ 如何看c語言標准庫函數的源代碼
很遺憾,標准庫中的函數結合了系統,硬體等的綜合能力,是比較近機器的功能實現,所以大部分是用匯編完成的,而且已經導入到了lib和dll里了,就是說,他們已經被編譯好了,似乎沒有代碼的存在了.
能看到的也只有dll中有多少函數被共享.
第三方可能都是dll,因為上面也說了,dll是編譯好的,只能看到成品,就可以隱藏代碼,保護自己的知識產權,同時也是病毒的歸宿...... 當然,除了DLL的確還存在一種東西,插件程序~~~
Ⅲ C語言庫函數qsort源代碼
void __fileDECL qsort (
void *base,
size_t num,
size_t width,
int (__fileDECL *comp)(const void *, const void *)
)
#endif /* __USE_CONTEXT */
{
char *lo, *hi; /* ends of sub-array currently sorting */
char *mid; /* points to middle of subarray */
char *loguy, *higuy; /* traveling pointers for partition step */
size_t size; /* size of the sub-array */
char *lostk[STKSIZ], *histk[STKSIZ];
int stkptr; /* stack for saving sub-array to be processed */
/此或老* validation section */
_VALIDATE_RETURN_VOID(base != NULL || num == 0, EINVAL);
_VALIDATE_RETURN_VOID(width > 0, EINVAL);
_VALIDATE_RETURN_VOID(comp != NULL, EINVAL);
if (num < 2)
return; /* nothing to do */
stkptr = 0; /* initialize stack */
lo = (char *)base;
hi = (char *)base + width * (num-1); /* initialize limits */
/森升* this entry point is for pseudo-recursion calling: setting
lo and hi and jumping to here is like recursion, but stkptr is
preserved, locals aren't, so we preserve stuff on the stack */
recurse:
size = (hi - lo) /團基 width + 1; /* number of el's to sort */
/* below a certain size, it is faster to use a O(n^2) sorting method */
if (size <= CUTOFF) {
__SHORTSORT(lo, hi, width, comp, context);
}
else {
/* First we pick a partitioning element. The efficiency of the
algorithm demands that we find one that is approximately the median
of the values, but also that we select one fast. We choose the
median of the first, middle, and last elements, to avoid bad
performance in the face of already sorted data, or data that is made
up of multiple sorted runs appended together. Testing shows that a
median-of-three algorithm provides better performance than simply
picking the middle element for the latter case. */
mid = lo + (size / 2) * width; /* find middle element */
/* Sort the first, middle, last elements into order */
if (__COMPARE(context, lo, mid) > 0) {
swap(lo, mid, width);
}
if (__COMPARE(context, lo, hi) > 0) {
swap(lo, hi, width);
}
if (__COMPARE(context, mid, hi) > 0) {
swap(mid, hi, width);
}
/* We now wish to partition the array into three pieces, one consisting
of elements <= partition element, one of elements equal to the
partition element, and one of elements > than it. This is done
below; comments indicate conditions established at every step. */
loguy = lo;
higuy = hi;
/* Note that higuy decreases and loguy increases on every iteration,
so loop must terminate. */
for (;;) {
/* lo <= loguy < hi, lo < higuy <= hi,
A[i] <= A[mid] for lo <= i <= loguy,
A[i] > A[mid] for higuy <= i < hi,
A[hi] >= A[mid] */
/* The doubled loop is to avoid calling comp(mid,mid), since some
existing comparison funcs don't work when passed the same
value for both pointers. */
if (mid > loguy) {
do {
loguy += width;
} while (loguy < mid && __COMPARE(context, loguy, mid) <= 0);
}
if (mid <= loguy) {
do {
loguy += width;
} while (loguy <= hi && __COMPARE(context, loguy, mid) <= 0);
}
/* lo < loguy <= hi+1, A[i] <= A[mid] for lo <= i < loguy,
either loguy > hi or A[loguy] > A[mid] */
do {
higuy -= width;
} while (higuy > mid && __COMPARE(context, higuy, mid) > 0);
/* lo <= higuy < hi, A[i] > A[mid] for higuy < i < hi,
either higuy == lo or A[higuy] <= A[mid] */
if (higuy < loguy)
break;
/* if loguy > hi or higuy == lo, then we would have exited, so
A[loguy] > A[mid], A[higuy] <= A[mid],
loguy <= hi, higuy > lo */
swap(loguy, higuy, width);
/* If the partition element was moved, follow it. Only need
to check for mid == higuy, since before the swap,
A[loguy] > A[mid] implies loguy != mid. */
if (mid == higuy)
mid = loguy;
/* A[loguy] <= A[mid], A[higuy] > A[mid]; so condition at top
of loop is re-established */
}
/* A[i] <= A[mid] for lo <= i < loguy,
A[i] > A[mid] for higuy < i < hi,
A[hi] >= A[mid]
higuy < loguy
implying:
higuy == loguy-1
or higuy == hi - 1, loguy == hi + 1, A[hi] == A[mid] */
/* Find adjacent elements equal to the partition element. The
doubled loop is to avoid calling comp(mid,mid), since some
existing comparison funcs don't work when passed the same value
for both pointers. */
higuy += width;
if (mid < higuy) {
do {
higuy -= width;
} while (higuy > mid && __COMPARE(context, higuy, mid) == 0);
}
if (mid >= higuy) {
do {
higuy -= width;
} while (higuy > lo && __COMPARE(context, higuy, mid) == 0);
}
/* OK, now we have the following:
higuy < loguy
lo <= higuy <= hi
A[i] <= A[mid] for lo <= i <= higuy
A[i] == A[mid] for higuy < i < loguy
A[i] > A[mid] for loguy <= i < hi
A[hi] >= A[mid] */
/* We've finished the partition, now we want to sort the subarrays
[lo, higuy] and [loguy, hi].
We do the smaller one first to minimize stack usage.
We only sort arrays of length 2 or more.*/
if ( higuy - lo >= hi - loguy ) {
if (lo < higuy) {
lostk[stkptr] = lo;
histk[stkptr] = higuy;
++stkptr;
} /* save big recursion for later */
if (loguy < hi) {
lo = loguy;
goto recurse; /* do small recursion */
}
}
else {
if (loguy < hi) {
lostk[stkptr] = loguy;
histk[stkptr] = hi;
++stkptr; /* save big recursion for later */
}
if (lo < higuy) {
hi = higuy;
goto recurse; /* do small recursion */
}
}
}
/* We have sorted the array, except for any pending sorts on the stack.
Check if there are any, and do them. */
--stkptr;
if (stkptr >= 0) {
lo = lostk[stkptr];
hi = histk[stkptr];
goto recurse; /* pop subarray from stack */
}
else
return; /* all subarrays done */
}
Ⅳ c語言atoi函數源代碼
c語言atoi函數源代絕禪碼:
int atoi(char n[])
{int i,y=0;
for(i=0;n[i]>='0'悔好 && n[i]<='9';i++)
y=y*10+n[i]-'碧宏鉛0';
return y;
}
Ⅳ C語言源代碼是什麼
數字版「拼圖」游戲C源代碼:
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
int i, j, r, k; //i、j、r用於循環, k存放隨機數值
int m, n; // m、n是當前空位的下標, t標記排序是否成功
int a[4][4]; //存儲4×4共16個數字的數組
void show(void); //輸出數組表格
void csh(void); //初始化界面
int yes(void); //判斷排序是否成功
void up(void); //數字向上移動到空位(空位則下移)
void down(void); //數字向下移
void left(void); //數字向左移
void rght(void); //數字向右移
void inkey(void); //按鍵操作
void gtxy(int x, int y) ; //控制游標移動的函數
int main(void)
{ while(1)
{csh( );
while(1)
{ inkey();
show();
if ( yes( ) )
{gtxy(6,12); printf("你成功了! 再來一局y/n?"); break;}
}
if(getch( )== ʹnʹ)break;
}
return 0;
}
void csh(void)
{r=0;
CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下兩行是隱藏游標的設置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
for(i=0;i<4;i++) //給數組a依序賦值
for(j=0;j<4;j++)
{ if (i==3 && j==3) a[i][j]=0;
else a[i][j]=1+r++;
}
a[3][3]=a[1][1]; a[1][1]=0; //把a[3][3]與a[1][1]的值交換一下
m=1; n=1;
srand((unsigned)time(0)); //初始化隨機數發生器
for(r=0;r<500;r++) //將數組各值打亂
{k=rand( )%(4); //取0-3隨機數,分別代表上下左右四個方向
switch(k)
{ case 0: { up( );break; }
case 1: {down( );break; }
case 2: {left( );break; }
case 3: {rght( ); break; }
}
}
printf(" 數字拼圖");
printf(" ┌──────┬──────┬──────┬──────┐");
printf(" │ │ │ │ │");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │ │ │ │ │");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │ │ │ │ │");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │ │ │ │ │");
printf("
└──────┴──────┴──────┴──────┘");
show( );
}
void show(void)
{for(i=0;i<4;i++)
for(j=0;j<4;j++) //gtxy(7*j+9, 2*i+4)是游標到指定位置輸出數字
{gtxy(7*j+9,2*i+4); if(a[i][j]==0)printf(" │");
else if(a[i][j]>9)printf(" %d │",a[i][j]);
else printf(" %d │",a[i][j]);
}
}
void inkey(void)
{ int key;
key=getch( );
switch(key)
{ case 72: { up( ); break;}
case 80: {down( ); break; }
case 75: {left( ); break; }
case 77: {rght( );break;}
}
}
void up(void)
{ if (m!=3) //移動時要考慮空位"0"是否已經在邊界
{ a[m][n]=a[m+1][n]; m++; a[m][n]=0; }
}
void down(void)
{ if (m!=0)
{a[m][n]=a[m-1][n]; m--; a[m][n]=0; }
}
void left(void)
{ if (n!=3)
{ a[m][n]=a[m][n+1]; n++; a[m][n]=0;}
}
void rght(void)
{ if (n!=0)
{ a[m][n]=a[m][n-1]; n--; a[m][n]=0; }
}
int yes(void)
{ r=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{ if (a[i][j]!=1+r++) return (r==16)?1:0; }
}
void gtxy(int x, int y) //控制游標移動的函數
{ COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
Ⅵ 求C語言中的庫函數的源代碼 如printf()函數,我要它的源代碼
在stdio.h中。如果是數學函數如sin()等的,在math.h中。而string類的函數則在string.h中。自己看吧
Ⅶ 尋 c語言函數fwrite和fread的源代碼
fwrite源代碼為:
size_t fwrite (const void* ptr,size_t size,size_t nmemb,FILE *fp);
頭文件在search.h中,有的在stddef.h中
fread源代碼為:
size_t fread(const void* ptr,size_t size,size_t nmemb,FILE *fp);
函數參數與fwrite相同
Ⅷ C語言庫函數源代碼在哪裡有看
有安裝vs2008或2010嗎,在安裝目錄下面的VC/src中自帶有源代碼。比如我的就在
D:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src中。沒有的話發給你
Ⅸ 如何看c語言標准庫函數的源代碼
1、首先標准只是規定了這些函數的介面和具體的運行效率的要求,這些函數具體是怎麼寫得要看各個編譯器的實現和平台。
2、例如使用的編譯器是visual studio,微軟提供了一部分C運行時(CRT)的源碼,裡面會有memcpy,strcpy之類的函數的實現,在visual studio 2005下的路徑是C:Program FilesMicrosoft Visual Studio 8VCcrtsrc。
Ⅹ 哪裡可以找到 c語言 函數的原代碼
如果安裝的是擾殲Visual studio6中的VC++,那麼有一橘螞些函數可以在這裡面找到:
X:\Program Files\Microsoft Visual Studio\VC98\CRT\SRC
其中X是安裝程序的盤符(一般是C)
但是好像不全,有些不是
http://www.aspx.cn/html/program/c++/504/49101.html
這里可以看到一些C語言字元串函數的源代碼
1. strlen(),計算字元串長度
int strlen(const char string)
{
int i=0;
while(string[i]) i++;
return i;
}
2. strcpy(), 字元串拷貝.
char *strcpy(char *destination, const char *source)
{
while(*destinaton++=*source++);
return (destination-1);
}
3. strcat(), 字元串的連接.
char *strcat(char *target,const char *source)
{
char *original=target;
while(*target) target++; // Find the end of the string
while(*target++=*source++);
return(original);
}
4. streql(), 判斷兩個字元串是否相等.
int streql(char *str1,char *str2)
{
while((*str1==*str2)&&(*str1))
{
str1++;
str2++;
}
return((*str1==NULL)&&(*str2==NULL));
}
5. strchr(), 在字元串中緩伍沖查找某個字元.
char *strchr(const char *string,int letter)
{
while((*string!=letter)&(*string))
string++;
return (string);
}
6. chrcnt(), 計算某個字元在字元串中出現的次數.
int chrcnt(const char *string,int letter)
{
int count=0;
while(*string)
if(*string==letter)count++;
return count;
}
7. strcmp(), 判斷兩個字元串是否相等.
int strcmp(const char *str1,const char *str2)
{
while((*str1==*str2)&&(*str1))
{
str1++;
str2++;
}
if((*str1==*str2)&&(!*str1)) //Same strings
return o;
else if((*str1)&&(!*str2)) //Same but str1 longer
return -1;
else if((*str2)&&(!*str1)) //Same but str2 longer
else
return((*str1>*str2)?-1:1);
}