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);
}