1.输入一个字符串,判断是否是VC++的关键字
(1)没有调用 strcmp()函数
觉得应该是一个非常简单的程序,但是调试了好几天,都没有结果,麻烦看看!
#include<iostream.h>
void main()
{
int i,j;
char s[11],str[3][12]={"auto","while","static_cast"};//只写了几个
cout<<"input a tring:";
cin>>s;
for(i=0;i<3;i++)
{if(s[0]!=str[i][0])
continue;
else
{
for(j=0;j<11;j++)
if(s[j]==str[i][j]&&s[j]!='\0'&&str[i][j]!='\0')
continue;
else
{cout<<"the string is not a keyword"<<endl;
break;}
}
cout<<"the string is a keyword"<<endl;
}
}
(2)调用了,很简单,没问题
#include<iostream.h>
#include<string.h>
void main()
{
int i,k;
char s[11],str[3][12]={"auto","while","static_cast"};
cout<<"input a tring:";
cin>>s;
for(i=0;i<3;i++)
{k=strcmp(s,str[i]);
if(k==0)
{cout<<" the string is a keyword"<<endl;
break;}
continue;}
cout<<"the string is not a keyword"<<endl;
}
2.输入一个式子,将其转换成词法记号流如:
position=initial+rate*60
输出:position
=
initial
+
rate
*
60
>??????????????????????没有一点思路
[此贴子已经被作者于2007-9-23 11:37:58编辑过]