KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I came across something really weird when I wrote a little lotto program in C++ called "lotto.cpp". Everything was fine until I wrote the write-to-file for my program. When I compiled, it showed me the following error: ld: can't open output file for writing: lotto, errno=21 for architecture x86_64 collect2: ld returned 1 exit status By coincidence, I changed the name of my program to "1.cpp", and all of a sudden it compiled without problems. It also worked when I changed the name to "test.cpp". I am really curious as to why this happened. Any Ideas? This happened on a MacBook Pro. If you want the code as well, just let me know! I know some people asked for the code. Here it is: #include <iostream> #include <fstream> using namespace std; const int NED = 10; const int VIKING = 6; const int NORMAL = 7; const int MAX = 10; void quickSort(int arr[], int left, int right); int checkDuplicates(int arr[], int length); int main (int argc, const char *argv[]) { int i, j, k, ans; char ans2; int lottoNumbers[MAX]; ofstream out("Lotto.txt", ios::out | ios::app); srand((unsigned)time(NULL)); do { do { cout << "\n\nDo you want to play Viking Lotto (press 6), or normal Lotto (press 7): "; cin >> ans; }while(ans != VIKING && ans != normal); (ans == VIKING) ? cout << "\nViking Lotto:\n" : cout << "\n\nnormal Lotto:\n"; (ans == VIKING) ? out << "\nViking Lotto:\n" : out << "\n\nnormal Lotto:\n"; for (i = 0; i < NED; i++) //10 rows { for (j = 0; j < ans; j++) //6 or 7 columns { (ans == VIKING) ? lottoNumbers[j] = (rand() % 48) + 1 : lottoNumbers[j] = (rand() % 34) + 1; } if(checkDuplicates(lottoNumbers, ans) != -1)
Tags (comma-separated)
Save Edits
Cancel