c语言编程如何去除括号中的字符

2025-04-07 23:30:54
推荐回答(1个)
回答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;}