Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have got a text file which a lot of useless texts in brackets i.e. (something). There are no nested braket at all. Can something help me to figure out a script in VB or C++ that can delete all occurrences of brackets and stuffs inside them without the layout of the text. I appreciate your help in advance.

You can use this function to delete any text, including the open and close chars, between any two chars (brackets, etc.).
You pass it a buffer that is 10 bytes longer than the text file you want to read into it and zeroed ( c++: new() or c: calloc() ).
Write 'buf' back out to a file to see your modifications.
#include <string.h>int delbrackets(
char *buf,
char openC,
char closeC)
{
char *p,*q;for(p=q=buf;*p;)
{
p=strstr(p,openC);
if(p==NULL)return 0;q=strstr(p,closeC);
if(q==NULL)return 0;memcpy(p,++q,strlen(q)+1);
}
return 0;
}jorgen

I made a mistake, the args for delbrackets()
should all be strings, I forgot the '*' on openC and closeC:The correct version is:
int delbrackets(
char *buf,
char *openC,
char *closeC)

![]() |
differences between Start...
|
Email form for webpage??
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |