日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

对于指针传入函数,却最终没有改变指针的值的问题

發布時間:2025/5/22 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 对于指针传入函数,却最终没有改变指针的值的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原本寫了一個函數,用于去掉字符串中的空格

void CMy21EnAIDlg::Onencyai() {CString strEncryptionData;m_txt_EncryptionData.GetWindowText(strEncryptionData);char Enddata[128]={0};char Endata[128]={0};int index = 0;char temp;int idata=0;if( strEncryptionData.IsEmpty()){AfxMessageBox("SN和秘鑰為空,請重新輸入");return ;}char* c;c=strEncryptionData.GetBuffer(strEncryptionData.GetLength()); int length=strEncryptionData.GetLength();fun.CStringDelBlank(c,length);strEncryptionData=c;//Endata=c;strcpy(Endata , c); } void CPublicFunction::CStringDelBlank(char *strEncryptionData,int length) {int idata = 0;char temp;char Enddata[128]={0}; // int length=strEncryptionData.GetLength();for(int i=0;i<length;i++){if(strEncryptionData[i]==' '){continue;}else{Enddata[idata]=strEncryptionData[i];idata++;}}//strEncryptionData="";//strEncryptionData=Enddata;memcpy(strEncryptionData,Enddata,strlen(Enddata)+1);}

發現并不能改變數組的值,原因是兩個數組的地址不一樣。=等號只是傳地址,而memcpy是將要改變字符串的整個空間值全都改變了

#include<stdio.h> void m(char *a) {printf("%p\n",&a);} void main() {// TODO: Add your control notification handler code here//char b[]={0,1,2,3,5,6,85,5};char b[]="{0,1,2,3,5,6,85,5}";char *s=b;printf("%p\n",&s);printf("%p\n",b);m(s);system ("pause");}

總結

以上是生活随笔為你收集整理的对于指针传入函数,却最终没有改变指针的值的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。