14、 编写一个函数reverse(s)将字符串s中的字符位置颠倒过来.例如,字符串abcdefg中的字符位置颠倒后变为
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/25 02:39:48
14、 编写一个函数reverse(s)将字符串s中的字符位置颠倒过来.例如,字符串abcdefg中的字符位置颠倒后变为gfedcba.
![14、 编写一个函数reverse(s)将字符串s中的字符位置颠倒过来.例如,字符串abcdefg中的字符位置颠倒后变为](/uploads/image/z/15032425-49-5.jpg?t=14%E3%80%81+%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E5%87%BD%E6%95%B0reverse%28s%29%E5%B0%86%E5%AD%97%E7%AC%A6%E4%B8%B2s%E4%B8%AD%E7%9A%84%E5%AD%97%E7%AC%A6%E4%BD%8D%E7%BD%AE%E9%A2%A0%E5%80%92%E8%BF%87%E6%9D%A5.%E4%BE%8B%E5%A6%82%2C%E5%AD%97%E7%AC%A6%E4%B8%B2abcdefg%E4%B8%AD%E7%9A%84%E5%AD%97%E7%AC%A6%E4%BD%8D%E7%BD%AE%E9%A2%A0%E5%80%92%E5%90%8E%E5%8F%98%E4%B8%BA)
Dev-C++ 4.9.9编译通过了,= =,不知道是不是要这样的……随意写的,见谅
额,最下面的测试代码 运行错误…… 思路就这样了……
后面,错误大致调试了一下,在下面,当然,这个函数有待改进……
话说,这DevC++还真不好用,单说这调试……唉,VC实在是太肥了……
void Reverse(char *str)
{
if (NULL == str)
{
return ;
}
int iLen = 0; // length of the C-style string
int iTemp;
char cTemp;
// the string will terminated with char '\0'
while (str[iLen++] != '\0'); // get the length of the C string
for (int t=0; t<(iLen/2); ++t)
{
// swap the char(front and last)
iTemp = iLen - t - 2;
cTemp = str[t];
str[t] = str[iTemp];
str[iTemp] = cTemp;
} // end for
} // end Reverse
这是我写的测试的源文件代码,错误在于传递时的参数……
// main.cpp
#include <cstdlib>
#include <iostream>
using namespace std;
#ifndef NULL
#define NULL 0
#endif // NULL
void Reverse(char *str);
int main(int argc, char *argv[])
{
// 这是原来的定义,是字符指针,而非数组!注意!
// char *szTest = "ok,this is a test!"; // 错误在于这里!
char szTest[] = "ok,this is a test!"; // 这样可以得到想要的结果了,RT
cout << szTest << endl;
Reverse(szTest);
cout << "Reversed:\n";
cout << szTest << endl;
system("PAUSE");
return EXIT_SUCCESS;
} // main
void Reverse(char *str)
{
if (NULL == str)
{
return ;
}
int iLen = 0; // length of the C-style string
int iTemp;
char cTemp;
// the string will terminated with char '\0'
while (str[iLen++] != '\0'); // get the length of the C string
for (int t=0; t<(iLen/2); ++t)
{
// swap the char(front and last)
iTemp = iLen - t - 2;
cTemp = str[t];
str[t] = str[iTemp];
str[iTemp] = cTemp;
} // end for
}
![](http://img.wesiedu.com/upload/a/17/a17ac2045da9b4e61017ce79bcbed392.jpg)
额,最下面的测试代码 运行错误…… 思路就这样了……
后面,错误大致调试了一下,在下面,当然,这个函数有待改进……
话说,这DevC++还真不好用,单说这调试……唉,VC实在是太肥了……
void Reverse(char *str)
{
if (NULL == str)
{
return ;
}
int iLen = 0; // length of the C-style string
int iTemp;
char cTemp;
// the string will terminated with char '\0'
while (str[iLen++] != '\0'); // get the length of the C string
for (int t=0; t<(iLen/2); ++t)
{
// swap the char(front and last)
iTemp = iLen - t - 2;
cTemp = str[t];
str[t] = str[iTemp];
str[iTemp] = cTemp;
} // end for
} // end Reverse
这是我写的测试的源文件代码,错误在于传递时的参数……
// main.cpp
#include <cstdlib>
#include <iostream>
using namespace std;
#ifndef NULL
#define NULL 0
#endif // NULL
void Reverse(char *str);
int main(int argc, char *argv[])
{
// 这是原来的定义,是字符指针,而非数组!注意!
// char *szTest = "ok,this is a test!"; // 错误在于这里!
char szTest[] = "ok,this is a test!"; // 这样可以得到想要的结果了,RT
cout << szTest << endl;
Reverse(szTest);
cout << "Reversed:\n";
cout << szTest << endl;
system("PAUSE");
return EXIT_SUCCESS;
} // main
void Reverse(char *str)
{
if (NULL == str)
{
return ;
}
int iLen = 0; // length of the C-style string
int iTemp;
char cTemp;
// the string will terminated with char '\0'
while (str[iLen++] != '\0'); // get the length of the C string
for (int t=0; t<(iLen/2); ++t)
{
// swap the char(front and last)
iTemp = iLen - t - 2;
cTemp = str[t];
str[t] = str[iTemp];
str[iTemp] = cTemp;
} // end for
}
![](http://img.wesiedu.com/upload/a/17/a17ac2045da9b4e61017ce79bcbed392.jpg)
14、 编写一个函数reverse(s)将字符串s中的字符位置颠倒过来.例如,字符串abcdefg中的字符位置颠倒后变为
没看懂啊给定程序中,函数fun的功能是:在形参所指字符串中的每个数字字符之后插入一个*号.例如,形参s所指的字符串为:d
有一个包含了n个字符的字符串.编写一个函数,将此字符串从头开始共m个字符作为一个子字符串复制到另一个字符数组中,并输出该
c ,改错题1、给定程序MODI1.C中函数fun的功能是:先将在字符串s中的字符按正序存放到t串中,然后把s中的字符按
编写一个函数,输入一个字符串,内有数字和非数字字符,将其中连续的数字作为一个整数依次存放到数组a中
这就是整个程序,fun函数的功能是:把一个整数转换成字符串,并倒序存在字符数组s中.例如n=123,则s=“321”#i
C语言,编写一个函数squeeze(s1,s2),能从字符串s1中删去所有与字符串s2中相同的字符.
C语言编程 求思路求一个字符串中的最长子串(串:连续的相同字符构成)例如:aabbbaacddf 则找出 bbb
帮忙看看哪里错了~~编写一个,功能是:返回字符串中指定字符的个数.在主函数中读入一个字符串,并读入一个要统计的字符,调用
认真帮我看看吧,编写函数void fun(char s[ ]),其功能是:将s所指字符串中所有下标为奇数的位置上的字母转
函数fun的功能是:在形参s所指字符串中寻找与参数c相同的字符,并在其后插入一个与之相同的字符,若找不到则不作任何处理
编写函数,求出字符串(含数字、字母)中ASC II 码最大的字符.字符串在主函数中读入(使用gets函数).