-
why does'nt this work..
The peice of the program compiles and executes on a regular C compiler, but when I use a C++ compiler it compiles but crashes my system..
The C compiler is pacific c the C++ compiler is dev c++.
The program checks for brakets and deletes space between them..
int i. j = 0;
char file[20] = "<a h ref="sys tem.tx t">
for (i=0;i<numchar;i++){
if (file[i]=='<'){
do{
if (file[i]==' ')
i++;
if (file[i]!=' '){
file[j]=file[i];
j++;
}
}while (file[i]!='>'&&file[i]);
}
file[j]='\0';
when i comment out the j++ it compiles and runs..
-
Sorry I can't I'm at work..But it's basically the algorithm..It's like I can't insert another counter in the while loop without the program crashing..
Just set the array size bigger and initialize numchar to zero as an int..
-
Code:
int main ( ) {
char file[] = "wibble wibble <a h ref=\"sys tem.tx t\"> zippy bong";
int i, j, inscope = 0;
for ( i = 0, j = 0 ; file[i] != '\0' ; i++ ) {
if ( !inscope && file[i] == '<' ) inscope = 1;
if ( inscope && file[i] == '>' ) inscope = 0;
if ( !inscope || (inscope && file[i] != ' ') ) {
file[j++] = file[i];
}
}
file[j] = '\0';
printf( "%s\n", file );
return 0;
}
But "aref" should remain "a ref", so I think you need to revise your spec.