📄 subject_47983.htm
字号:
<p>
序号:47983 发表者:fanghehe 发表日期:2003-07-26 22:07:20
<br>主题://下面是一个把小写字母变成大写字母的程序,我有问题:
<br>内容://下面是一个把小写字母变成大写字母的程序,我有问题:<BR>#include <ctype.h><BR>void convert(char *);<BR>void main()<BR>{<BR>//为什么char *p="charsters and $23,29";不可以<BR> char p[]="charsters and $23,29";//却可以执行 ??<BR> cout<<"the ariginal arry is"<<p<<endl;<BR> <BR> convert(p);<BR> cout<<"the coverted arry is"<<p;<BR><BR><BR>}<BR>void convert(char *s)<BR>{<BR> while(*s!='\0')<BR> {if(*s>='a'&&*s<='z')<BR> *s=toupper(*s);<BR> ++s;<BR> }<BR>}<BR><BR>//下面这个程序有3个莫名其妙的错误,有高手请说说是为什么?<BR>#include <iostream.h><BR>#include <iomanip.h><BR>void bubble(int [],const int,int(*)(int ,int));<BR>int ascending(int ,int);<BR>int descending(int ,int);<BR>int main()<BR>{<BR> const int arraysize=10;<BR> int order,<BR> counter,<BR> a[arraysize]={2,6,4,8,10,12,89,68,45,37};<BR> for(counter=0;counter<arraysize;counter++)<BR> cout<<" "<<a[counter];<BR> <BR> cin>>order;<BR> <BR> if(order==1)<BR> {<BR> bubble(a,arraysize,ascending);<BR> }<BR> else<BR> bubble(a,arraysize,descending);<BR> for(counter=0;counter<arraysize;counter++)<BR> cout<<" "<<a[counter];<BR> cout<<endl;<BR> return 0;<BR>}<BR>void bubble(int work[], const int size, int (*)compare(int ,int))//这里是一个指向函数的指针;<BR>{<BR> void swap(int ,int);<BR> for(int pass=1;pass<size;pass++)<BR> for(int i=0;i<size-1;i++)<BR> if((*compare)(work[i],work[i+1]))<BR> swap(work[i],work[i+1]);<BR>}<BR>void swap(int &a,int &b)<BR>{ <BR> int temp;<BR> temp=a;<BR> a=b;<BR> b=temp;<BR>}<BR>int ascending(int a,int b)<BR>{<BR> return a<b;<BR>}<BR>int descending(int a,int b)<BR>{<BR> return a>b;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:罗兹维尔 回复日期:2003-07-27 10:28:52
<br>内容:你的第一个程序是犯了初学者经常会犯的错误<BR>看看这个<BR><BR>void main()<BR>{<BR> char *p = "hello";<BR> *p = 'H';<BR> cout << p << endl;<BR>}<BR><BR>这是错误的,原因就是字符串常量是放在代码区的<BR>而代码区不允许改变
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:fanghehe 回复日期:2003-07-28 11:38:37
<br>内容:谢谢,那第二个题怎么出现了莫名其妙的三个错误了呢?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:罗兹维尔 回复日期:2003-08-02 11:56:50
<br>内容:#include <iostream.h><BR>#include <iomanip.h><BR><BR>void bubble(int work[], const int size, int (*compare)(int ,int));<BR>int ascending(int ,int);<BR>int descending(int ,int);<BR>void swap(int &a,int &b);<BR><BR>int main()<BR>{<BR> const int arraysize=10;<BR> int order,<BR> counter,<BR> a[arraysize]={2,6,4,8,10,12,89,68,45,37};<BR> for(counter=0;counter<arraysize;counter++)<BR> cout<<" "<<a[counter];<BR> <BR> cin>>order;<BR> <BR> if(order==1)<BR> {<BR> bubble(a,arraysize,ascending);<BR> }<BR> else<BR> bubble(a,arraysize,descending);<BR> for(counter=0;counter<arraysize;counter++)<BR> cout<<" "<<a[counter];<BR> cout<<endl;<BR> return 0;<BR>}<BR><BR><BR>void bubble(int work[], const int size, int (*compare)(int ,int))<BR>{<BR> for(int pass=1;pass<size;pass++)<BR> for(int i=0;i<size-1;i++)<BR> if((*compare)(work[i],work[i+1]))<BR> swap(work[i],work[i+1]);<BR>}<BR><BR><BR>void swap(int &a,int &b)<BR>{ <BR> int temp;<BR> temp=a;<BR> a=b;<BR> b=temp;<BR>}<BR><BR><BR>int ascending(int a,int b)<BR>{<BR> return a<b;<BR>}<BR><BR><BR>int descending(int a,int b)<BR>{<BR> return a>b;<BR>} <BR><BR><BR><BR>编译错误没有了,你的算法我没看<BR>你是不是先学PASCAL再学C的?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:fanghehe 回复日期:2003-08-02 15:49:37
<br>内容:???阁下为什么这么问啊,没有啊,我没学过pascal<BR>我这个代码是从c++ 大学教程里面抄的
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:罗兹维尔 回复日期:2003-08-02 19:52:50
<br>内容:原来是书上的,我看到那程序在函数里定义函数<BR>还以为你以前是学PASCAL的
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -