很简单的啊明明没有有关问题,为什么却总是出错呢,多谢大家帮小弟我看看
很简单的啊!明明没有问题,为什么却总是出错呢,谢谢大家帮我看看!
#include <string.h>
#include <iostream.h>
// 我的目的是想去除字符串的含有年份的字符:200?,200?年,200?年度。
void main()
{
char str[100]= "2003年度2005高峰2003年2006会议 ";
int v=0;
for(v=0;v <100;)
{
if(str[v]==0)
break;
if(str[v]== '2 ' && str[v+1]== '0 ' && str[v+2]== '0 ' && str[v+3]> 47 && str[v+3] <58)
{
if(str[v+4]==-60 && str[v+5]==-22) // -60 -22 为年的机内码
{
if(str[v+6]==-74 && str[v+7]==-56) //-74 -56 为度的机内码
strcpy(str+v,str+8); //覆盖 "200?年度 " 8位
else
strcpy(str+v,str+6); //覆盖 "200?年 " 6位
}
else
strcpy(str+v,str+4); //覆盖 "200? " 4位
}
else
v++;
}
cout < <str < <endl; //为什么这里的结果总不是正确的呢?
}
------解决方案--------------------
str[100]= "2003年度2005高峰2003年2006会议 ";
if str含有200 && 200后面的下一个字符是数字,则删除200X,搞定
------解决方案--------------------
up
------解决方案--------------------
再说一点,请不要写如此复杂的逻辑表达式.
------解决方案--------------------
格式让我看的眼睛处于游离态- -
------解决方案--------------------
200?是年度。
还要判断200?后面是数字或别的字符,否则不是年度。
------解决方案--------------------
#include <stdio.h>
void main()
{
char str[100]= "2003年度2005高峰2003年2006会议 ";
for(int i=0;i <35;i++)
{
if(str[i]== '2 ')
{
for(int j=i;j <35;j++)
{
str[j]=str[j+4];
}
}
}
printf( "%s\n ",str);
}
------解决方案--------------------
LZ写的我看不大明白,不知道写的对不对,
在下刚出道请多指教!
#include <string.h>
#include <iostream.h>
// 我的目的是想去除字符串的含有年份的字符:200?,200?年,200?年度。
void main()
{
char str[100]= "2003年度2005高峰2003年2006会议 ";
int v=0;
for(v=0;v <100;)
{
if(str[v]==0)
break;
if(str[v]== '2 ' && str[v+1]== '0 ' && str[v+2]== '0 ' && str[v+3]> 47 && str[v+3] <58)
{
if(str[v+4]==-60 && str[v+5]==-22) // -60 -22 为年的机内码
{
if(str[v+6]==-74 && str[v+7]==-56) //-74 -56 为度的机内码
strcpy(str+v,str+8); //覆盖 "200?年度 " 8位
else
strcpy(str+v,str+6); //覆盖 "200?年 " 6位
}
else
strcpy(str+v,str+4); //覆盖 "200? " 4位
}
else
v++;
}
cout < <str < <endl; //为什么这里的结果总不是正确的呢?
}
------解决方案--------------------
str[100]= "2003年度2005高峰2003年2006会议 ";
if str含有200 && 200后面的下一个字符是数字,则删除200X,搞定
------解决方案--------------------
up
------解决方案--------------------
再说一点,请不要写如此复杂的逻辑表达式.
------解决方案--------------------
格式让我看的眼睛处于游离态- -
------解决方案--------------------
200?是年度。
还要判断200?后面是数字或别的字符,否则不是年度。
------解决方案--------------------
#include <stdio.h>
void main()
{
char str[100]= "2003年度2005高峰2003年2006会议 ";
for(int i=0;i <35;i++)
{
if(str[i]== '2 ')
{
for(int j=i;j <35;j++)
{
str[j]=str[j+4];
}
}
}
printf( "%s\n ",str);
}
------解决方案--------------------
LZ写的我看不大明白,不知道写的对不对,
在下刚出道请多指教!