欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

C語言平移函數(shù) c語言的移位運(yùn)算

c語言改錯(cuò),要求實(shí)現(xiàn)數(shù)據(jù)平移。謝謝哈。

mov 函數(shù)中使用了指針 b,但未對(duì)它賦值,它指向的內(nèi)存是未知的,因此出錯(cuò)。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供微山網(wǎng)站建設(shè)、微山做網(wǎng)站、微山網(wǎng)站設(shè)計(jì)、微山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、微山企業(yè)網(wǎng)站模板建站服務(wù),十年微山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

要實(shí)現(xiàn)數(shù)據(jù)平移,比較簡單的方法是先將它復(fù)制一份,再平移。這樣, mov 函數(shù)可寫為

void mov(int *x,int n,int m)

{

int *b, i, j;

b = (int *)calloc(n, sizeof(int));

if (b == NULL) {

printf("allocate memory failed!\n");

exit(0);

}

memcpy(b, x, n*sizeof(int));

for (i=0; in; i++) {

j = (i+n-m)%n;

x[i] = b[j];

}

free(b);

}

程序中用到了內(nèi)存分配的函數(shù)及內(nèi)存復(fù)制函數(shù),因此需要包含 stdlib.h 和 string.h 庫。

C語言數(shù)組平移問題

int a[8] = {xxxxxx};

int b[8];

int m;

int i, j = 0;

scanf("%d",m);

for(i = m;i8;i++)

{

b[j++] = a[i];

}

for(i = 0;im;i++)

{

b[j++] = a[i];

}

利用c語言怎樣對(duì)bmp圖像進(jìn)行平移的操作?

位圖平移沒有這方面的庫函數(shù),必須自己來實(shí)現(xiàn),下面是位圖平移的參考代碼:

#include "stdafx.h"

#includewindows.h

#includestdio.h

#includemath.h

int _tmain(int argc, _TCHAR* argv[])

{

int width;

int height;

RGBQUAD *pTableColor;

unsigned char *pBmpBuf1,*pBmpBuf2;

BITMAPFILEHEADER bfhead;

BITMAPINFOHEADER bihead;

//讀出源圖像的信息

FILE *fpr=fopen("E:\\picture\\dog.bmp","rb");

if(fpr==0)

return 0;

fread(bfhead,14,1,fpr);

fread(bihead,40,1,fpr);

width=bihead.biWidth;

height=bihead.biHeight;

int LineByte=(width*8/8+3)/4*4;

pTableColor=new RGBQUAD[256];

fread(pTableColor,sizeof(RGBQUAD),256,fpr);

pBmpBuf1=new unsigned char[LineByte*height];

fread(pBmpBuf1,LineByte*height,1,fpr);

fclose(fpr);

//將處理后的圖像賦值為白色

pBmpBuf2=new unsigned char[LineByte*height];

for(int i=0;iheight;i++)

for(int j=0;jwidth;j++)

{

unsigned char *p;

p=(unsigned char*)(pBmpBuf2+LineByte*i+j);

(*p)=255;

}

//左右平移功能的實(shí)現(xiàn)

int t;

printf("請(qǐng)輸入左平移或右平移的大小t(左移t0,右移t0):");

scanf("%d",t);

int k=abs(t);

printf("%d",k);

if(t0)

{

if(t=(-width))

{

for(int i=0;iheight;i++)

for(int j=0;j(width-k);j++)

{

unsigned char *p1,*p2;

p1=pBmpBuf1+LineByte*i+j+k;

p2=pBmpBuf2+LineByte*i+j;

(*p2)=(*p1);

}

}

}

else

{

if(t=width)

{

for(int i=0;iheight;i++)

for(int j=k;jwidth;j++)

{

unsigned char *p1,*p2;

p1=pBmpBuf1+LineByte*i+j-k;

p2=pBmpBuf2+LineByte*i+j;

(*p2)=(*p1);

}

}

}

//保存處理后的圖像

FILE *fpw=fopen("dog.bmp","wb");

fwrite(bfhead,14,1,fpw);

fwrite(bihead,40,1,fpw);

fwrite(pTableColor,sizeof(RGBQUAD),256,fpw);

fwrite(pBmpBuf2,LineByte*height,1,fpw);

fclose(fpw);

return 0;

}

新聞標(biāo)題:C語言平移函數(shù) c語言的移位運(yùn)算
標(biāo)題URL:http://chinadenli.net/article12/hjipgc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)品牌網(wǎng)站建設(shè)標(biāo)簽優(yōu)化定制開發(fā)微信公眾號(hào)建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作