String comparison

Simply, I have two strings. No matter what you type in, the strcmp returns 1. Here's the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	int accountnumber[11];

	cout<<"Your account number is: ";

	for(int i=0; i<10; i++)
	{
		accountnumber[i+1] = rand() % 9;
		cout<<accountnumber[i+1];
	}
	cout<<endl;

        cout<<"Please enter the account number.";
	cin>>accountguess;
	int test = strcmp(accountnumber, accountguess);
	cout<<test<<endl;


test always returns 1.
You're using strcmp to compare an array of integers for one.

I think you probably want that to be a char array. Also, you'll never know what the first value of that array is.

These may help:
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/
Last edited on
strcmp is a function for comparing arrays of char but you are trying to compare arrays of int.
Fixed. Thank you.
Topic archived. No new replies allowed.