0

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!

Edited by WaltP: Added CODE Tags

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by sdsda
0

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

0

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.

0

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.

Edited by chiwawa10: n/a

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.