CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Posts
    18

    Doesnt Display Characters

    Fixing~
    Last edited by Guru_Kid; April 24th, 2009 at 01:34 AM.

  2. #2
    Join Date
    Jan 2009
    Location
    Salt Lake City, Utah
    Posts
    82

    Re: Doesnt Display Characters

    I haven't used arrays in a while, but don't you need to use a literal or static constant for the array size in the declaration? Try doing this instead:
    Code:
    int *acres;
    acres = new int[record_count];
    In fact, to simplify things, and likely increase performance because you won't have to parse the file twice, just use a STL container and one method that populates the container from the file. There are also standardized, optimized sorting methods for STL containers.
    Last edited by Etherous; April 23rd, 2009 at 06:53 AM.
    Intel Core Duo Macbook w/ Mac OS 10.5.6
    gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1

  3. #3
    Join Date
    Apr 2008
    Posts
    725

    Re: Doesnt Display Characters

    doesnt compile for me

    also:
    Code:
    while (inData >> next_value)
    {
      number_of_values++;
    }
    you're trying to stream a letter into a double - that will fail and number_of_values will stay at 0, therefore your 'things' will be empty, therefore nothing will be output to the console.
    Last edited by Amleto; April 23rd, 2009 at 03:57 PM.

  4. #4
    Join Date
    Feb 2009
    Posts
    18

    Re: Doesnt Display Characters

    [QUOTE=Amleto;1835835]doesnt compile for me

    [/ QUOTE]


    The reason its probably not compling is because you don't have the text file.

    char data_filename[] = "C:\\Data\\Letters.txt". The file itself is just randomized letters [A, E, O, I]

    Quote Originally Posted by Etherous View Post
    I haven't used arrays in a while, but don't you need to use a literal or static constant for the array size in the declaration? Try doing this instead:
    Code:
    int *acres;
    acres = new int[record_count];
    In fact, to simplify things, and likely increase performance because you won't have to parse the file twice, just use a STL container and one method that populates the container from the file. There are also standardized, optimized sorting methods for STL containers.
    Thanks for the tip but the characters aren't displaying
    Last edited by Guru_Kid; April 23rd, 2009 at 08:02 PM.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Doesnt Display Characters

    The reason its probably not compling is because you don't have the text file.
    No.

    Compiling means to take the code you posted in your first message, and compile it, not run it.

    If I took your code as you posted it, and attempted to compile it, here is a sample of the errors:
    Code:
    Thank you for testing your code with Comeau C/C++!
    Tell others about http://www.comeaucomputing.com/tryitout !
    
    Your Comeau C/C++ test results are as follows:
    
    Comeau C/C++ 4.3.10.1 (Oct  6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
    Copyright 1988-2008 Comeau Computing.  All rights reserved.
    MODE:strict errors C++ C++0x_extensions
    
    "ComeauTest.c", line 15: error: identifier "count_file_values" is undefined
      int record_count = count_file_values(data_filename);
                         ^
    
    "ComeauTest.c", line 16: error: expression must have a constant value
      int acres[record_count];
                ^
    
    "ComeauTest.c", line 18: error: identifier "cout" is undefined,
            Perhaps use "std::cout", or "using namespace std;"?
            Did you #include <iostream>?"
      cout << "The letters are: \n";
      ^
    
    "ComeauTest.c", line 22: error: identifier "display_array" is undefined
      display_array(acres, record_count);
      ^
    
    "ComeauTest.c", line 30: error: identifier "fstream" is undefined
      fstream inData; 
      ^
    
    "ComeauTest.c", line 34: error: name followed by "::" must be a class or namespace
              name... Wild guess: Did you #include the right header?
      inData.open(input_filename, ios::in); 
                                  ^
    
    "ComeauTest.c", line 37: error: identifier "cout" is undefined,
            Perhaps use "std::cout", or "using namespace std;"?
            Did you #include <iostream>?"
      cout << "\n\nError opening input data file: " << input_filename << "\n\n";
      ^
    
    "ComeauTest.c", line 39: error: identifier "EXIT_FAILURE" is undefined
      exit(EXIT_FAILURE);
           ^
    
    "ComeauTest.c", line 39: error: identifier "exit" is undefined
      exit(EXIT_FAILURE);
      ^
    
    "ComeauTest.c", line 56: error: identifier "fstream" is undefined
      fstream inData; 
      ^
    
    "ComeauTest.c", line 58: error: name followed by "::" must be a class or namespace
              name... Wild guess: Did you #include the right header?
      inData.open(input_filename, ios::in); 
                                  ^
    
    "ComeauTest.c", line 61: error: identifier "cout" is undefined,
            Perhaps use "std::cout", or "using namespace std;"?
            Did you #include <iostream>?"
      cout << "\n\nError opening input data file: " << input_filename << "\n\n";
      ^
    
    "ComeauTest.c", line 63: error: identifier "EXIT_FAILURE" is undefined
      exit(EXIT_FAILURE);
           ^
    
    "ComeauTest.c", line 63: error: identifier "exit" is undefined
      exit(EXIT_FAILURE);
      ^
    
    "ComeauTest.c", line 81: error: identifier "cout" is undefined,
            Perhaps use "std::cout", or "using namespace std;"?
            Did you #include <iostream>?"
      cout << things [i] << " " ;
      ^
    
    "ComeauTest.c", line 114: error: identifier "cout" is undefined,
            Perhaps use "std::cout", or "using namespace std;"?
            Did you #include <iostream>?"
      cout << "\n\n";
      ^
    
    "ComeauTest.c", line 115: error: identifier "system" is undefined
      system("PAUSE");
      ^
    
    17 errors detected in the compilation of "ComeauTest.c".
    
    In strict mode, with -tused, Compile failed
    Instead of hastily putting stuff in the message window and having us to figure out what's missing, post a complete example, including headers, so that all we need to do is paste it into the compiler window, and have no compilation errors.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured