c语言编程如何去除括号中的字符
1个回答
展开全部
要考虑括号内不一定是数字,还要考虑括号内不全是数字和不在括号内的数字都不能选取。举例代码如下:
1234567891011121314
//#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int main(void){ char *a="<1234> i love china.<123> i love china.<12> i love china."; int x,i,k; for(i=0;a[i];i++) if(a[i]=='<' && a[i+1]>='0' && a[i+1]<='9'){ sscanf(a+i+1,"%d%n",&x,&k); printf("%d ",x); i+=k; } printf("\n"); return 0;}
1234567891011121314
//#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int main(void){ char *a="<1234> i love china.<123> i love china.<12> i love china."; int x,i,k; for(i=0;a[i];i++) if(a[i]=='<' && a[i+1]>='0' && a[i+1]<='9'){ sscanf(a+i+1,"%d%n",&x,&k); printf("%d ",x); i+=k; } printf("\n"); return 0;}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询