The practice program of C on point
On The of point program Practice
2023-09-14 09:08:01 时间
//字符反向排列 //vision 1.2 #include<stdio.h> void reverse_string( char *str ) { char *string;//第一个字符位置 char *last_char;//最后一个字符位置 //for( last_char = str; ; last_char++ ) // if( *last_char == '\0' ) // break; // for( last_char = str; *last_char != '\0'; last_char++ ) // ; /* **设置last_char存储最后一个字符位置 */ for( last_char = &str[0]; *last_char != '\0'; last_char++ ) ; string = &str[0]; last_char--; /* **交换前后指针指向位置的值 前指针添加 后指针降低 */ while( string < last_char ) { char temp; temp = *string; *string++ = *last_char; *last_char-- = temp; } printf( "%s", str ); } int main( void ) { char str[10] = {"abcdef"}; reverse_string(str); return 0; }在不使用库函数情况下 自己还是把这个库函数里有的函数敲出来了。仅仅是有个迷惑的地方。这是终究版本号,但之前有个版本号,输出始终仅仅有源字符串的一半长度。同一时候也是反转了的。不理解。
希望有明确的朋友看见后能够告知下。小子我在此谢谢了~源代码例如以下:
//字符反向排列 //vision 1.2 //程序结果错误 为什么? //就眼下 我推測问题出在数组的指针上 //直接对原数组的指针进行操作 应该找个中间量存储開始指针。 //未完待续···· #include<stdio.h> void reverse_string( char *str ) { char *last_char;//最后一个字符位置 //for( last_char = str; ; last_char++ ) // if( *last_char == '\0' ) // break; // for( last_char = str; *last_char != '\0'; last_char++ ) // ; /* **设置last_char存储最后一个字符位置 */ for( last_char = &str[0]; *last_char != '\0'; last_char++ ) ; last_char--; /* **交换前后指针指向位置的值 前指针添加 后指针降低 */ while( str < last_char ) { char temp; temp = *str; *str++ = *last_char; *last_char-- = temp; } printf( "%s", str ); } int main( void ) { char str[10] = {"abcdxuf"}; reverse_string(str); return 0; }仅仅是多了个中间变量而已,这是为什么呢?
相关文章
- java错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu
- ICDAR2017 Competition on Reading Chinese Text in the Wild(RCTW-17) 介绍
- [Next.js] Consume Next.js API routes with the SWR library on the client-side
- [Angular2 Router] Load Data Based on Angular 2 Route Params
- PRVF-5486 : The NTP Daemon On The Indicated Nodes Is Not Using UDP Port 123 (文档 ID 1378412.1)
- SparkR(R on Spark)编程指南 含 dataframe操作
- 解决mysqldump: [Warning] Using a password on the command line interface can be insecure.
- [Mise] Update a count state value with the x-on event listener directive in Alpine JS
- 【时间管理】猴子理论 ”monkey-on-the-back” Analogy
- [HTML5] Show Images of Differing Resolutions Depending on the Viewport Width with srcset
- [Node.js] node-persist: localStorage on the server
- [服务器时区问题]PHP Warning: strftime(): It is not safe to rely on the system's timezone set
- 图解Spark On Yarn cluster模式运行机制
- NLP:LSTM之父眼中的深度学习十年简史《The 2010s: Our Decade of Deep Learning / Outlook on the 2020s》的参考文献
- 神经网络贷款风险评估(base on keras and python )
- Install the .NET SDK or the .NET Runtime on Ubuntu
- 【文献学习】Deep-Waveform: A Learned OFDM Receiver Based on Deep Complex Convolutional Networks
- 【Transformer】18、ACMix:On the Integration of Self-Attention and Convolution
- Django报错:No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.