Thread: Stray Error while compiling

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    23

    Stray Error while compiling

    Hello, I am still new with programming in C through Fedora terminal.

    I am trying to get an early start on my lab that is on Wed. - so I copy and paste the code and I get Stray errors. I don't know id the "\" is the cause and before I start removing code from the lab, I want to know what is causing this issue. If I comment the lines out, the program while compile so I know it happens to do with those two lines. I "google" the errors and the results seem to be the inputting characters that aren't ASC. Can someone please explain this issue to happen because this is happening on more than one lab for the future. Thanks!

    Code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #define MYPORT 4950 // the port users will be connecting to
    #define MAXBUFLEN 100
    int main(void)
    {
            int sockfd;
            struct sockaddr_in my_addr; // my address information
            struct sockaddr_in their_addr; // connector’s address information
            socklen_t addr_len;
            int numbytes;
            char buf[MAXBUFLEN];
            if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
                    perror("socket");
                    exit(1);
            }
    my_addr.sin_family = AF_INET; // host byte order
            my_addr.sin_port = htons(MYPORT); // short, network byte order
            my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
            memset(&(my_addr.sin_zero), ’\0’, 8); // zero the rest of the struct
            if (bind(sockfd, (struct sockaddr *)&my_addr,
                    sizeof(struct sockaddr)) == -1) {
                    perror("bind");
                    exit(1);
            }
            addr_len = sizeof(struct sockaddr);
            if ((numbytes=recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,
                    (struct sockaddr *)&their_addr, &addr_len)) == -1) {
                    perror("recvfrom");
                    exit(1);
            }
            printf("got packet from %s\n",inet_ntoa(their_addr.sin_addr));
            printf("packet is %d bytes long\n",numbytes);
            buf[numbytes] = ’\0’;
                    printf("packet contains \"%s\"\n",buf);
            close(sockfd);
            return 0;
    }
    Error Code:
    Code:
    listener.c: In function ‘main’:
    listener.c:27: error: stray ‘\342’ in program
    listener.c:27: error: stray ‘\200’ in program
    listener.c:27: error: stray ‘\231’ in program
    listener.c:27: error: stray ‘\’ in program
    listener.c:27: error: stray ‘\342’ in program
    listener.c:27: error: stray ‘\200’ in program
    listener.c:27: error: stray ‘\231’ in program
    listener.c:41: error: stray ‘\342’ in program
    listener.c:41: error: stray ‘\200’ in program
    listener.c:41: error: stray ‘\231’ in program
    listener.c:41: error: stray ‘\’ in program
    listener.c:41: error: stray ‘\342’ in program
    listener.c:41: error: stray ‘\200’ in program
    listener.c:41: error: stray ‘\231’ in program

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    23
    It seems if i change ’\0’ to '\0' - it can compile. Is this correct?

    from:
    memset(&(my_addr.sin_zero), ’\0’, 8);
    to
    memset(&(my_addr.sin_zero), '\0', 8);

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Yeah, it usually means you've copied code from some website, which has been munged to "look good" by using different quote characters.
    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.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    indeed, you have to use a simple quote '...' to enclose a character

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    23
    Thanks for the information and reason for the code error - Thanks again!

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    1
    i am trying the following program and it gives some errors while compiling. i cant figure out what the error is. can someone please help me? thanks in advance.


    Code:
    #include<stdio.h>
    #include<math.h>
    float detrm( float[][], float );
    void cofact( float[][], float );
    void trans( float[][], float[][], float );
    main()
    {
        float a[ 25 ][ 25 ], k, d;
        int i, j;
        printf( "ENTER THE ORDER OF THE MATRIX:\n" );
        scanf( "%f", &k );
        printf( "ENTER THE ELEMENTS OF THE MATRIX:\n" );
     
        for ( i = 0;i < k;i++ )
            {
                for ( j = 0;j < k;j++ )
                    {
                        scanf( "%f", &a[ i ][ j ] );
                    }
            }
     
        d = detrm( a, k );
        printf( "THE DETERMINANT IS=%f", d );
     
        if ( d == 0 )
            printf( "\nMATRIX IS NOT INVERSIBLE\n" );
        else
            cofact( a, k );
    }
     
    /******************FUNCTION TO FIND THE DETERMINANT OF THE MATRIX************************/
     
    float detrm( float a[ 25 ][ 25 ], float k )
    {
        float s = 1, det = 0, b[ 25 ][ 25 ];
        int i, j, m, n, c;
     
        if ( k == 1 )
            {
                return ( a[ 0 ][ 0 ] );
            }
        else
            {
                det = 0;
     
                for ( c = 0;c < k;c++ )
                    {
                        m = 0;
                        n = 0;
     
                        for ( i = 0;i < k;i++ )
                            {
                                for ( j = 0;j < k;j++ )
                                    {
                                        b[ i ][ j ] = 0;
     
                                        if ( i != 0 && j != c )
                                            {
                                                b[ m ][ n ] = a[ i ][ j ];
     
                                                if ( n < ( k – 2 ) )
                                                    n++;
                                                else
                                                    {
                                                        n = 0;
                                                        m++;
                                                    }
                                            }
                                    }
                            }
     
                        det = det + s * ( a[ 0 ][ c ] * detrm( b, k – 1 ) );
                        s = -1 * s;
                    }	
            }
     
        return ( det );
    }
     
    /*******************FUNCTION TO FIND COFACTOR*********************************/
     
    void cofact( float num[ 25 ][ 25 ], float f )
    {
        float b[ 25 ][ 25 ], fac[ 25 ][ 25 ];
        int p, q, m, n, i, j;
     
        for ( q = 0;q < f;q++ )
            {
                for ( p = 0;p < f;p++ )
                    {
                        m = 0;
                        n = 0;
     
                        for ( i = 0;i < f;i++ )
                            {
                                for ( j = 0;j < f;j++ )
                                    {
                                        b[ i ][ j ] = 0;
     
                                        if ( i != q && j != p )
                                            {
                                                b[ m ][ n ] = num[ i ][ j ];
     
                                                if ( n < ( f – 2 ) )
                                                    n++;
                                                else
                                                    {
                                                        n = 0;
                                                        m++;
                                                    }
                                            }
                                    }
                            }
     
                        fac[ q ][ p ] = pow( -1, q + p ) * detrm( b, f – 1 );
                    }
            }
     
        trans( num, fac, f );
    }
     
    /*************FUNCTION TO FIND TRANSPOSE AND INVERSE OF A MATRIX**************************/
     
    void trans( float num[ 25 ][ 25 ], float fac[ 25 ][ 25 ], float r )
     
    {
        int i, j;
        float b[ 25 ][ 25 ], inv[ 25 ][ 25 ], d;
     
        for ( i = 0;i < r;i++ )
            {
                for ( j = 0;j < r;j++ )
                    {
                        b[ i ][ j ] = fac[ j ][ i ];
                    }
            }
     
        d = detrm( num, r );
        inv[ i ][ j ] = 0;
     
        for ( i = 0;i < r;i++ )
            {
                for ( j = 0;j < r;j++ )
                    {
                        inv[ i ][ j ] = b[ i ][ j ] / d;
                    }
            }
     
        printf( "\nTHE INVERSE OF THE MATRIX:\n" );
     
        for ( i = 0;i < r;i++ )
            {
                for ( j = 0;j < r;j++ )
                    {
                        printf( "\t%f", inv[ i ][ j ] );
                    }
     
                printf( "\n" );
            }
    }


    the errors are...


    [ERROR CODE]
    /home/samy/programs/inversematrix/main.cpp:61: error: stray ‘\342’ in program
    /home/samy/programs/inversematrix/main.cpp:61: error: stray ‘\200’ in program
    /home/samy/programs/inversematrix/main.cpp:61: error: stray ‘\223’ in program
    /home/samy/programs/inversematrix/main.cpp:72: error: stray ‘\342’ in program
    /home/samy/programs/inversematrix/main.cpp:72: error: stray ‘\200’ in program
    /home/samy/programs/inversematrix/main.cpp:72: error: stray ‘\223’ in program
    /home/samy/programs/inversematrix/main.cpp:104: error: stray ‘\342’ in program
    /home/samy/programs/inversematrix/main.cpp:104: error: stray ‘\200’ in program
    /home/samy/programs/inversematrix/main.cpp:104: error: stray ‘\223’ in program
    /home/samy/programs/inversematrix/main.cpp:115: error: stray ‘\342’ in program
    /home/samy/programs/inversematrix/main.cpp:115: error: stray ‘\200’ in program
    /home/samy/programs/inversematrix/main.cpp:115: error: stray ‘\223’ in program
    /home/samy/programs/inversematrix/main.cpp:3: error: multidimensional array must have bounds for all dimensions except the first
    /home/samy/programs/inversematrix/main.cpp:4: error: multidimensional array must have bounds for all dimensions except the first
    /home/samy/programs/inversematrix/main.cpp:5: error: multidimensional array must have bounds for all dimensions except the first
    /home/samy/programs/inversematrix/main.cpp:5: error: multidimensional array must have bounds for all dimensions except the first
    /home/samy/programs/inversematrix/main.cpp: In function ‘int main()’:
    /home/samy/programs/inversematrix/main.cpp:22: error: cannot convert ‘float (*)[25]’ to ‘float’ for argument ‘1’ to ‘float detrm(float)’
    /home/samy/programs/inversematrix/main.cpp:28: error: cannot convert ‘float (*)[25]’ to ‘float’ for argument ‘1’ to ‘void cofact(float)’
    /home/samy/programs/inversematrix/main.cpp: In function ‘float detrm(float (*)[25], float)’:
    /home/samy/programs/inversematrix/main.cpp:61: error: expected ‘)’ before numeric constant
    /home/samy/programs/inversematrix/main.cpp:62: error: expected ‘)’ before ‘;’ token
    /home/samy/programs/inversematrix/main.cpp:72: error: expected ‘)’ before numeric constant
    /home/samy/programs/inversematrix/main.cpp: In function ‘void cofact(float (*)[25], float)’:
    /home/samy/programs/inversematrix/main.cpp:104: error: expected ‘)’ before numeric constant
    /home/samy/programs/inversematrix/main.cpp:105: error: expected ‘)’ before ‘;’ token
    /home/samy/programs/inversematrix/main.cpp:115: error: expected ‘)’ before numeric constant
    /home/samy/programs/inversematrix/main.cpp:119: error: cannot convert ‘float (*)[25]’ to ‘float’ for argument ‘1’ to ‘void trans(float)’[/CODE]
    Last edited by baba3007; 02-03-2011 at 03:19 PM.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    1. Don't pick a random irrelevant three-year-old thread to post in, but make your own.

    2. When it says "multidimensional array must have bounds for all dimensions except the first", they mean it. You can't pass arbitrary-in-all-dimensions arrays around.

    3. You have weird symbols on line 61, 72, 104, and 115. So use a normal symbol instead. A rough guess is that you have something like a fancy - sign instead of a normal - sign.

    EDIT: In fact the three symbols listed, 0xE2, 0x80, 0x93, are the UTF-8 equivalent of the Unicode U+2013, which conveniently enough is "En Dash".
    Last edited by tabstop; 02-03-2011 at 03:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does: 'error: stray ‘o357’ in program' mean?
    By Phanixis in forum Linux Programming
    Replies: 8
    Last Post: 12-04-2010, 01:48 AM
  2. C compiling / error: stray ‘\’ in program
    By Elya in forum C Programming
    Replies: 5
    Last Post: 07-02-2009, 08:20 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 01:09 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM