c語言自相關函數
這幾個函數的原型在<stdio.h>中定義
/* Return the value of envariable NAME, or NULL if it doesn't exist. */
extern char *getenv (__const char *__name) __THROW __nonnull ((1)) __wur;
/* The SVID says this is in <stdio.h>, but this seems a better place. */
/* Put STRING, which is of the form "NAME=VALUE", in the environment.
If there is no `=', remove NAME from the environment. */
extern int putenv (char *__string) __THROW __nonnull ((1));
/* Set NAME to VALUE in the environment.
If REPLACE is nonzero, overwrite an existing value. */
extern int setenv (__const char *__name, __const char *__value, int __replace)
__THROW __nonnull ((2));
/* Remove the variable NAME from the environment. */
extern int unsetenv (__const char *__name) __THROW __nonnull ((1));
㈡ c語言裡面怎麼判斷一個數是不是整數有沒有相關的函數
float
x;
int
y;
scnaf("%f",&x);
y=x;
if
(
y==x
)
printf("%d是整數。\n",(int)x);
else
printf("%f不是整數。\n",x);
當然也可以用簡單的條件判斷:if
(
(int)x==x
)
...
㈢ c語言的相關運算
第一題因為1>0 而值為10
第二題,答案為4無爭議。
你說的問題是編譯器的問題,例如 x++*x--+--x 的問題,類似vc6.0編譯器會先將x++或x--的x值都取出來然後再做運算
可能和正常的理解不太一樣,但編譯器就是這樣編譯的,你可以多用幾個例子試一試,就知道了 。
㈣ 有一個數組,有1024個點,在C語言中實現這個數組的自相關函數R()
不會c語言啊
㈤ 有沒有什麼書籍或者資料可以詳細講講c語言圖形庫graphics等相關函數用法
C/C++主要功能是對文件的操作,但不包括圖形操作,你看過哪本C/C++的書教你畫窗體,控制項啥的? 一般來說,C/C++里的圖形處理都需要第三方開發的庫,如OpenGL.或者一些編譯器像Dev-C里自帶的有繪圖函數,如果你用的是Linux環境,可以考慮使用KDE,QT等在C語言下開發圖形處理.QT的書有賣的,我們學校圖書館就有. 關於圖形函數庫的使用手冊你可以到官網去查,很完整,不過幾乎全是英語,就看你水平如何了.書店裡這方面的書實在是少.
㈥ 求教C語言 指針 自定義函數相關問題 請教出錯原因
把main中的void average();改成void average(float *,int);。
把main中的void search();改成void search(float (*)[4],int);。
把main中的void average(*score,12);改成average(*score,12);。
把main中的voidsearch(score,2);改成search(score,2);。
若有問題再說。以上僅是語法錯誤……
㈦ C語言中的include< dir.h>中的相關函數和作用
chdir()改變當前目錄的函數
原形:int chdir(const char *path)
功能:把由path指定的目錄改為當前目錄。path參數中可以指定驅動器號,如「a:\\ddd」, 但只是改變該驅動器上的當前目錄,對當前活動驅動器上的當前目錄無影響。
返回值:0(成功);-1(失敗)
頭文件:dir.h
=======================================================================================
findfirst()函數和findnext()函數
調用方式:整形數=findfirst(文件名,&結構變數名,屬性常數組合(如0x26));其中定義struct ffblk 結構變數名;
原形:int findfirst(path,buffer,attr)和int findnext(buffer)
char *path;//要檢索的文件名
struct ffblk
{
char ff_reserved[21];
char ff_attrib;//被檢索的文件屬性
unsigned ff_ftime;//最後修改的時間
//(0-4位:秒數/2;5-10位:分數;11-15位:小時數)
unsigned ff_fdate;//最後修改的日期
//(0-4位:日;5-8位:月;9-15位:年減1980)
long ff_fsize;//文件大小
char ff_name[13];//組名
}*buffer;
int attr;//要檢索的文件屬性
功能:檢索由path和attr指定的文件,把結果返回到buffer。findfirst返回關於第一個指定文件的信息,findnext繼續檢索。
返回值:0(檢索成功),-1(沒有找到指定的文件)
屬性常數:
FA_NORMAL(0x00) 含意:Normal file, no attributes
FA_RDONLY(0x01) 含意:只讀
FA_HIDDEN(0x02) 含意:隱含文件
FA_SYSTEM(0x04) 含意:系統文件
FA_LABEL(0x08) 含意:卷標
FA_DIREC(0x10) 含意:子目錄
FA_ARCH(0x20) 含意:修改的文件Archive
頭文件:dir.h(dos.h)
====================================================================================
fnmerge()建立文件路徑函數
原形:void fnmerge(char *path,const char *drive,const char *dir, const char *name,const char *ext)
功能:合成drive:\dir\name.ext,放在path
頭文件:dir.h
fnsplit()分解完整的路徑名函數
原形:int fnsplit(char *path,const char *drive,const char *dir,const char *name,const char *ext)
功能:把文件名路徑path分成4個部分存放。
其中drive中有冒號;dir中有開始和結尾的反斜杠;ext包括開始圓點
返回值:如果有擴展名,則 返回值&EXTENSION!=0
如果有文件名,則 返回值&FILENAME!=0
如果有目錄名,則 返回值&DIRECTORY!=0
如果有驅動器號,則返回值&DIRVE!=0
頭文件:dir.h
====================================================================================
getcurdir()讀取指定驅動器的當前目錄的函數
原形:int getcurdir(int drive,char directory)
drive=0(預設);1(A驅動器);...
directory用來存放目錄名,不包括驅動器名,不以反斜杠開始。
返回值:0(調用成功);1(出錯)
頭文件:dir.h
getcwd()讀取當前目錄的函數
原形:char *getcwd(char *buf,int buflen)
功能:讀取當前目錄的完整路徑名(包括驅動器名),最長為buflen個位元組,存放在buf中。如果buf為NULL,函數將分配一個buflen位元組長的緩沖區,以後可將本函數的返回值作為free函數的參數來釋放該緩沖區。
返回值:若buf非空,調用成功返回buf,出錯返回NULL;若buf為NULL,返回指向已經分配的內存緩沖區地址。
頭文件:dir.h
getdisk()讀取當前磁碟驅動器號函數
原形:int getdisk(void)
功能:取得當前驅動器號(0=A;1=B;....)
頭文件:dir.h
======================================================================================
mkdir()創建目錄函數
原形:int mkdir(const char *path)
功能:按給定的路徑建立一個新的目錄
頭文件:dir.h
返回值:0(成功);-1(失敗)
mktemp()建立一個唯一的文件名的函數
原形:char *mktemp(char *template)
功能:使用一個唯一的文件名來替換字元串template,並返回template。
頭文件:dir.h
======================================================================================
rmdir()刪除目錄函數
原形:int rmdir(const char *path)
注意:刪除的目錄不能是當前目錄,不是根目錄,是空目錄
返回值:0(成功);-1(操作出錯)
頭文件:dir.h
searchpath()按dos路徑查找一個文件的函數
原形:char *searchpath(const char *file)
用法:p=searchpath("文件名"); 先定義char *p;
功能:搜索dos路徑(環境變數中的path=....)來定位由file給出的文件。
返回值:指向完整路徑名字元串的指針。定位失敗返回NULL。
頭文件:dir.h
segread()讀段寄存器函數
原形:void segread(struct SREGS *segp)
作用:把當前寄存器的值保存到SREGS型機構變數segp中。
segs.cs=代碼段寄存器的值;
segs.ds=數據段寄存器的值;
segs.es=附加段寄存器的值;
segs.ss=堆棧段寄存器的值;
setdisk()設置當前驅動器的函數
原形:int setdisk(int drive)
功能:把由drive指定的驅動器修改成當前驅動器,返回可使用的驅動器數。
頭文件:dir.h
settextstyle()顯示字元的當前設置函數
功能:設置當前輸出英文字元的字體、大小和方向。
調用方式:
void far settextstyle(int font,int direction,int charsize)
其中①參數font確定所選定的字體形狀,
DEFAULT_FONT 或0 是8×8點陣圖字體
TRIPLEX_FONT 或1 是三重矢量字體
SMALL_FONT 或2 是小號矢量字體
SANS_SERIF_FONT或3 是無襯線矢量字體
GOTHIC_FONT 或4 是哥特矢量字體
②參數rection字元的顯示方向,
HORIZ_DIR 或0 是水平方向
VERT_DIR 或1 是垂直方向
③參數charsize表示字元放大的倍數,其值為0到10。
setvect()設置中斷向量函數
setvect(int 中斷號,void interrupt(*中斷函數名))
功能:把中斷服務程序的地址裝入中斷向量表中。
調用方法:setvect(中斷號,中斷函數名即地址);
(1)得預先定義要代替原函數的新函數
void interrupt 中斷函數名(void)
{......}
(2)得先保留原中斷函數地址
void interrupt (*保留函數名)(void);
保留函數名=getvect(中斷號);
(3)事後得將原中斷函數地址裝迴向量表中
setvect(中斷號,保留函數名);
setviewport()建立視口的函數
原形: void far setviewport(int left,int top,int right,int bottom,int clip)
功能:用左上角坐標left,top和右下角坐標right,bottom建立一個視口,如果clip為1,則超出視口的輸出自動被剪裁掉;如果clip為0,則不被剪裁。
例:setviewport(0,0,100,100,1)建立對角線為0,0和100,100的視口,並帶有剪裁功能。
註:要清除當前視口,用函數clearnviewport()。
㈧ 如何用C語言直接定義自相關函數
#include<stdio.h>
floatdata[25]={1,2,3,4,5,6,7,8,9,10,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8};
floatr[15];
intN=10;
inti,m;
floatAutocorrelation(floatdata[],intN)
{for(m=0;m<5;m++){r[m]=0;}
for(m=0;m<N;m++)for(i=1;i<=N;i++)r[m]+=data[i]*data[i+m];
returnr[N-1];}
voidmain()
{for(m=0;m<5;m++)
{r[m]=Autocorrelation(data,N);
printf("%f
",r[m]);}
getch();
}
㈨ (c語言)文件相關函數的返回值
fgetc():成功時返回讀入的位元組數。錯誤或文件尾時返回EOF;
fputc():成功時返回寫入的位元組數。錯誤時返回EOF;
fgets():成功時返回字元串地址,錯誤或0讀入時返回NULL;
fputs():成功時返回一個非負整數,錯誤時返回EOF
fprintf():成功時返回寫入的位元組數,錯誤時返回負數(negative value)
fscanf():返回正確讀入項目(items)的個數,錯誤時返回EOF
fwrite():返回正確寫入項目的個數,錯誤時返回0
fread():返回正確讀入項目的個數,錯誤時返回0
fseek():成功返回0,錯誤返回-1。
㈩ C語言庫函數的相關概念
函數名:abort
功 能:異常終止一個進程
函數與形參類型:
void abort(void);
程序例:
#include <stdio.h>
#include <stdlib.h> int main(void)
{
printf(Calling abort()
);
abort();
return 0; /* This is never reached */
} 函數名:abs
功 能:計算整數num的值。返回整數num的絕對值
函數與參數類型:
int abs(num)
int num;
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
int number = -1234; printf(number: %d absolute value: %d
, number, abs(number));
return 0;
} 函數名: absread, abswirte
功 能:絕對磁碟扇區讀、寫數據
函數與形參類型:
int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
程序例:
/* absread example */ #include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h> int main(void)
{
int i, strt, ch_out, sector;
char buf[512]; printf(Insert a diskette into drive A and press any key
);
getch();
sector = 0;
if (absread(0, 1, sector, &buf) != 0)
{
perror(Disk problem);
exit(1);
}
printf(Read OK
);
strt = 3;
for (i=0; i<80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf(
);
return(0);
} 函數名:access
功 能:確定文件的訪問許可權
函數與形參類型:
int access(const char *filename, int amode);
程序例:
#include <stdio.h>
#include <io.h> int file_exists(char *filename); int main(void)
{
printf(Does NOTEXIST.FIL exist: %s
,
file_exists(NOTEXISTS.FIL) ? YES : NO);
return 0;
} int file_exists(char *filename)
{
return (access(filename, 0) == 0);
} 函數名: acos
功 能:計算並返回arccos(x)值、要求-1<=X<=1
函數與形參類型:
double acos(x)
double x;
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = acos(x);
printf(The arc cosine of %lf is %lf
, x, result);
return 0;
} 函數名:allocmem
功 能:分配DOS存儲段
函數與形參類型:
int allocmem(unsigned size, unsigned *seg);
程序例:
#include <dos.h>
#include <alloc.h>
#include <stdio.h> int main(void)
{
unsigned int size, segp;
int stat; size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &segp);
if (stat == -1)
printf(Allocated memory at segment: %x
, segp);
else
printf(Failed: maximum number of paragraphs available is %u
,
stat); return 0;
} 函數名:arc
功 能:畫一弧線
函數與形參類型:
void far arc(int x, int y, int stangle, int endangle, int radius);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 45, endangle = 135;
int radius = 100; /* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ); /* read result of initialization */
errorcode = graphresult(); /* an error occurred */
if (errorcode != grOk)
{
printf(Graphics error: %s
, grapherrormsg(errorcode));
printf(Press any key to halt:);
getch(); exit(1); /* terminate with an error code */
} midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor()); /* draw arc */
arc(midx, midy, stangle, endangle, radius); /* clean up */
getch();
closegraph();
return 0;
} 函數名: asctime
功 能:轉換日期和時間為ASCII碼
函數與形參類型:
char *asctime(const struct tm *tblock);
程序例:
#include <stdio.h>
#include <string.h>
#include <time.h> int main(void)
{
struct tm t;
char str[80]; /* sample loading of tm structure */ t. tm_sec = 1; /* Seconds */
t. tm_min = 30; /* Minutes */
t. tm_hour = 9; /* Hour */
t. tm_mday = 22; /* Day of the Month */
t. tm_mon = 11; /* Month */
t. tm_year = 56; /* Year - does not include century */
t. tm_wday = 4; /* Day of the week */
t. tm_yday = 0; /* Does not show in asctime */
t. tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ /* converts structure to null terminated
string */ strcpy(str, asctime(&t));
printf(%s
, str); return 0;
} 函數名::asin
功 能::計算並返回arcsin(x)值、要求-1<=X<=1
函數與形參類型:
double asin(x)
double x;
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = asin(x);
printf(The arc sin of %lf is %lf
, x, result);
return(0);
} 函數名: assert
功 能:測試一個條件並可能使程序終止
函數與形參類型:
void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h> struct ITEM {
int key;
int value;
}; /* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
assert(itemptr != NULL);
/* add item to list */
} int main(void)
{
additem(NULL);
return 0;
} 函數名:atan
功 能:計算並返回arctan(x)的值
函數與形參類型:
double atan(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = atan(x);
printf(The arc tangent of %lf is %lf
, x, result);
return(0);
} 函數名: atan2
功 能:計算並返回arctan(x/y)值
函數與形參類型:
double atan2(double y, double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 90.0, y = 45.0; result = atan2(y, x);
printf(The arc tangent ratio of %lf is %lf
, (y / x), result);
return 0;
} 函數名: atexit
功 能:注冊終止函數
函數與形參類型:
int atexit(atexit_t func);
程序例:
#include <stdio.h>
#include <stdlib.h> void exit_fn1(void)
{
printf(Exit function #1 called
);
} void exit_fn2(void)
{
printf(Exit function #2 called
);
} int main(void)
{
/* post exit function #1 */
atexit(exit_fn1);
/* post exit function #2 */
atexit(exit_fn2);
return 0;
} 函數名: atof
功 能:把str指向的ASCⅡ字元串轉換成一個double型整數返回雙精度的結果
函數與形參類型:
double atof(str)
char*str;
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
float f;
char *str = 12345.67; f = atof(str);
printf(string = %s float = %f
, str, f);
return 0;
} 函數名:atoi
功 能:
把str指向的ASCⅡz字元串轉換成一個整數。返回整數結果
函數與參數類型:
double atoi(str )
char *str;
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
int n;
char *str = 12345.67; n = atoi(str);
printf(string = %s integer = %d
, str, n);
return 0;
} 函數名:atol
功 能:
把字元串轉換成長整型數 。返回長整數結果
函數與參數類型:
long atol(str )
char *str;
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
long l;
char *str = 98765432; l = atol(lstr);
printf(string = %s integer = %ld
, str, l);
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
)) :
(printf(Unable to create directory
));
getch();
system(dir);
getch();
status = rmdir(asdfjklm);
(!status) ? (printf(Directory deleted
)) :
(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
,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
,
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
, 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
, 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
,destination);
return 0;
} 函數名: normvideo
功 能:選擇正常亮度字元
用 法:
void normvideo(void);
程序例:
#include <conio.h>
int main(void)
{
normvideo();
cprintf(NORMAL Intensity Text
);
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();
}