What is wron with my code?:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int i;
void myfunc(char scrpt);
  char scrpt;
    char scpt[10][200];
      int junk;
    
int main()
{
  int z;

    char scpt[10][200] = {
    "AAA", "A1",
    "BBB", "B1",
    "CCC", "C1",
    "DDD", "D1",
    "EEE", "E1" };
    srand((unsigned)time(NULL));
  z = rand()%1-10; 
  i = z;
  myfunc(scrpt);
  
  cout << "Well done!\n" << endl;

  return 0;
}

void myfunc(char scrpt[i])
{
	    if (i = 0, i < 5, i++)
{
  cout << scpt[i] << endl;
  cout << "\n";
  cout << "Press ENTER if you are ready to reveal c/v.\n"  << endl;
  cin >> junk;
  cout << "\n";
  cout << scpt[i++]  << endl;
  cout << "\n";
  cout << "\n";
  cout << "\n";
}
}

///////////////////////////////////////////////////////////

I am using Visual C++. The output reads as follows:
1>------ Build started: Project: eggberto-test, Configuration: Debug Win32 ------
1> eggberto test
1>c:\documents and settings\eggberto\my documents\visual studio 2010\projects\helloworlddd\helloworlddd\eggberto test(32): error C2057: expected constant expression
1>c:\documents and settings\eggberto\my documents\visual studio 2010\projects\helloworlddd\helloworlddd\eggberto test(32): error C2466: cannot allocate an array of constant size 0
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I realize that my current problem is passing my array to the function. Any help on that part? Thanks!

Recommended Answers

All 5 Replies

Please use code tags when you post code.

It looks like you need to change this:

void myfunc(char scrpt[i])

to this:

void myfunc(char* scrpt)

and this:

myfunc(scrpt);

to this:

myfunc(&scrpt);

Dave

Thank you, but now where "i" is in "void myfunc(char scrpt)", visual C++ highlights the "i" and says that it must have a constant value.

Your variables are confusing. The scrpt and scpt seems to be used incorrectly. In the myfunc(), you are not accessing the passed in parameter. And why are you passing in the global variable instead of char scpt[10][200]? There is no need to pass global variables around.

I would advice you to utilize more self-explanatory words for your variables.

Whoa! I didn't notice that they all didn't say scrpt! Sorry for such sloppy coding, this is my first program that I've designed. The array is just filled with junk text "AAA", I'm going to modify it with real words later.

This should be stickied

commented: ...what? -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.