Thread: Structure has gone wrong

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    101

    Structure has gone wrong

    The following code compiled and worked fine a few days ago but today when I ran it I got about 1550 warnings and some errors, some of which are:

    line 1 error: invalid preprocessing directive #i
    line 137 warning: null character (s) ignored (enabled by default)
    line 11 error: 'u' does not name a type


    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <sstream>
    
    using namespace std;
    
     struct Player
    {
        string surname;
        string initial;
        string firstname;
        string club;
        int normalgrade;
        int rapidgrade;
        string gradingnumber;
        int dmno;
    }Read, Hewins, Crane;
    
    int main ()
    {
        Read.surname = "Read";
        Read.initial = "F";
        Read.firstname = "Mike";
        Read.club = "Fakenham";
        Read.normalgrade=200;
        Read.rapidgrade=199;
        Read.gradingnumber="107456D";
        Read.dmno=14171;
    
        Hewins.surname = "Hewins";
        Hewins.initial = "P";
        Hewins.firstname = "Andrew";
        Hewins.club = "Fakenham";
        Hewins.normalgrade=20;
        Hewins.rapidgrade=19;
        Hewins.gradingnumber="199876H";
        Hewins.dmno=14201;
    
        Crane.surname = "Crane";
        Crane.initial = "D";
        Crane.firstname = "Stephen";
        Crane.club = "Norwich Dons";
        Crane.normalgrade=87;
        Crane.rapidgrade=76;
        Crane.gradingnumber="201654H";
        Crane.dmno=14223;
    
        cout<<Read.firstname<<" "<<Read.initial<<" "<<Read.surname<<" of "<<Read.club<<"Chess Club"<<endl;
        cout<<"His normal grade is "<<Read.normalgrade<<" and his rapidplay grade is "<<Read.rapidgrade<<endl;
        cout<<"His grading number is "<<Read.gradingnumber<<" and his ECF Direct Membership no is ";
        cout<<Read.dmno<<"."<<endl<<endl<<endl<<endl;
    
        cout<<Crane.firstname<<" "<<Crane.initial<<" "<<Crane.surname<<" of "<<Crane.club<<"Chess Club"<<endl;
        cout<<"His normal grade is "<<Crane.normalgrade<<" and his rapidplay grade is "<<Crane.rapidgrade<<endl;
        cout<<"His grading number is "<<Crane.gradingnumber<<" and his ECF Direct Membership no is ";
        cout<<Crane.dmno<<"."<<endl<<endl<<endl<<endl;
    
        cout<<Hewins.firstname<<" "<<Hewins.initial<<" "<<Hewins.surname<<" of "<<Hewins.club<<"Chess Club"<<endl;
        cout<<"His normal grade is "<<Hewins.normalgrade<<" and his rapidplay grade is "<<Hewins.rapidgrade<<endl;
        cout<<"His grading number is "<<Hewins.gradingnumber<<" and his ECF Direct Membership no is ";
        cout<<Hewins.dmno<<"."<<endl<<endl<<endl<<endl;
    
        return 0;
    }
    I am stumped by this, any comments?
    Last edited by JayCee++; 11-10-2011 at 09:25 AM. Reason: added another error

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    OK,

    if there are so many errors in a functioning program it probably has some typo errors. Anyway I can't really help you with that but take into consideration that you should check your errors in the order they appear.

    Meaning you don't fix your last error and move to the first at last. The first error surely exists, the second maybe depends to the first one. So check them in this order.

    Also take the line mentioned into consideration but only roughly. Numbers just indicate the LAST possible point of this error NOT this for sure. So you must check before that to find and error.

    Which is your first errors (just mention a few of them not a hundred)

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    the very first error is warning: null character (s) ignored (enabled by default)

    But this same code worked fine a few days ago, I haven't changed anything just reloaded the same program into Code::Blocks.

    I can't see any typose and I have checked again and again.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Something is very fishy about this:

    line 137 warning: null character (s) ignored (enabled by default)
    Since there are not 137 lines in that code. The line 11 error is also not from this, I think.

    I compiled the code you posted without error, after I removed windows.h since I do not have that and it does not seem to be required. The executable ran fine altho there are some spaces missing in your formatting.

    I don't use Code::Blocks, but obviously this is related to your use of the IDE and not your code.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    I don't believe this!!!
    I copied the entire code from the one that was giving all those errors and created a new project in Code::Blocks and pasted tha code in to it - it compiles and runs with no problem.

    Sorry to trouble you folks but just for interest sake the old one still gives all the errors if I load it into Code::Blocks.

    Very wierd!

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Sounds like you somehow saved the file as UTF-16 unicode, and the compiler didn't like the abundance of null bytes.

  7. #7
    Registered User
    Join Date
    Oct 2011
    Location
    Siloam Springs, Arkansas, United States
    Posts
    12
    I have had issues with importing files from different systems, or reloading removed files from a project. When loading the files, it's almost as if it's in a language that the compiler doesn't like or understand. Copying and pasting the code into a newly created file for that project sometimes helps with this. I am not sure why, but I am glad that you figured it out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-25-2010, 10:57 AM
  2. Replies: 9
    Last Post: 05-21-2007, 12:10 AM
  3. Replies: 4
    Last Post: 11-22-2006, 12:20 PM
  4. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  5. argggg!!! what's wrong with this structure???
    By Commonboy in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2002, 04:16 PM