C-style strings and arrays?

This is a discussion on C-style strings and arrays? within the C++ Programming forums, part of the General Programming Boards category; I trying to read data from a file to a c-string, then go through the string and convert the ascii ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    9

    Question C-style strings and arrays?

    I trying to read data from a file to a c-string, then go through the string and convert the ascii chars to 5 to 6 digits numbers, but im having trouble.
    The file looks looks like this: computer technology are part of just about everything...and so on
    I've already read it to the c-string but how do I the ascii to 5-6 digits numbers?
    Here's the code: What am I doing wrong?

    Code:
    void CheckArray(char inputfilename[], char charStringValue[])
    {
    // initialize variables
    
      ifstream input;
      char x;
      int index;
      int size;
      int y = 0;
    
      input.open(inputfilename);
    
      input >> charStringValue[x];
      while (input.good()) {
        cout << DecodeChar(charStringValue[x]) << " ";
        input >> charStringValue[x];
    
      }
      int DecodeChar(char c) {
        return (int (c - 32));
    
      }
    Last edited by Salem; 11-17-2012 at 11:46 AM. Reason: fixed fugly fonts

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    What do you mean '5-6 digit numbers'

    > return (int (c - 32));
    Any ASCII character going through this transformation is going to be between 0 and 95.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clarification with C-style Strings
    By StapleGun in forum C Programming
    Replies: 8
    Last Post: 10-30-2008, 08:46 PM
  2. Converting C++ Style strings...
    By LightsOut06 in forum C++ Programming
    Replies: 10
    Last Post: 10-26-2005, 04:02 PM
  3. More problems with C style strings
    By mousey in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2003, 02:52 PM
  4. converting c style strings to c++ strings
    By fbplayr78 in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:13 AM
  5. c-style string vs. c++-style strings
    By Mbrio in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 12:26 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21