Thread: why does'nt this work..

  1. #1

    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]=='<'){

    if (file[i]==' ')

    if (file[i]!=' '){

    }while (file[i]!='>'&&file[i]);


    when i comment out the j++ it compiles and runs..

  2. #2
    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..

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM
Website Security Test