Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++

Name: oppie 2010-11-03 14:30

hey Computers, quick C++ question

I get an <error: expected ',' or '...' before 'chArr'> in the first line when compiling this. Is there a special way of naming array arguments? I don't get it...

String::String(const char[] chArr)
{
  Length = 0;
  while(chArr[Length] != '\0')
    Length++;
  if (Length % 16 == 0)
    Capacity = Length;
  else
    Capacity = (Length / 16 + 1) * 16;
  Mem = new char[Capacity];
  for (int i = 0; i < Length; i++)
    Mem[i] = chArr[i];
}

Name: Anonymous 2010-11-21 19:11

Get back to Java

NO EXCEPTIONS

Name: Anonymous 2010-12-06 15:38

const is for pointers, char[] isn't a pointer

try: const char*

Name: Anonymous 2010-12-08 11:15

#include <iostream>

void wtf(const char chArr[])
{
  int length = 0;
  int capacity = 0;

  while(chArr[length] != '\0')
  {
    length++;
  }

  if (length % 16 == 0)
  {
    capacity = length;
  }
  else
  {
    capacity = (length / 16 + 1) * 16;
  }

  char * mem = new char[capacity];

  for (int i = 0; i < length; i++)
  {
    mem[i] = chArr[i];
  }

  delete mem;
}

int main(int argc, char * argv[])
{
  std::cout << "Daisy, Daisy...." << std::endl;

  wtf("What's the matter Dave?");

  return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List