Thread: C-style strings and arrays?

  1. #1
    Registered User
    Join Date
    Nov 2012

    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?

    void CheckArray(char inputfilename[], char charStringValue[])
    // initialize variables
      ifstream input;
      char x;
      int index;
      int size;
      int y = 0;
      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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

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, 07:46 PM
  2. Converting C++ Style strings...
    By LightsOut06 in forum C++ Programming
    Replies: 10
    Last Post: 10-26-2005, 03:02 PM
  3. More problems with C style strings
    By mousey in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2003, 01:52 PM
  4. converting c style strings to c++ strings
    By fbplayr78 in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 03: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