Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:20:44+00:00 2026-05-29T07:20:44+00:00

I came across something really weird when I wrote a little lotto program in

  • 0

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)        
            {
                for(k = 0; k < ans; k++)
                {
                    while(checkDuplicates(lottoNumbers, ans) == lottoNumbers[k])    
                    {
                        (ans == VIKING) ? lottoNumbers[k] = (rand() % 48) + 1 : lottoNumbers[k] = (rand() % 34) + 1;
                    }
                }
            }
            quickSort(lottoNumbers, 0, ans - 1);  
            cout << '\n';

            for(j = 0; j < ans; j++)
            {
                cout << lottoNumbers[j] << '\t'; 
                out << lottoNumbers[j] << '\t';
            }
            out << '\n';

        }   
        cout << "\n\n";


        cout <<"Another lottery ticket (Y/N) ";
        cin >> ans2;
    }while(ans2 == 'j' || ans2 == 'J');

    cout << "\n\nLOTTO NUMBERS WAS WRITTEN TO FILE...\n\n";

    return 0;
}

void quickSort(int arr[], int left, int right) 
{
    int i = left, j = right;
    int tmp;
    int mid = arr[(left + right) / 2];

    while (i <= j) 
    {
        while (arr[i] < mid)    i++;
        while (arr[j] > mid)    j--;
        if (i <= j) 
        {
            tmp = arr[i];
            arr[i] = arr[j];
            arr[j] = tmp;
            i++;
            j--;
        }
    };
    if (left < j)   quickSort(arr, left, j);
    if (i < right)  quickSort(arr, i, right);
}

int checkDuplicates(int arr[], int length)  
{                                       
    for(int i = 0; i < length; i++)
    {
        for(int j = i + 1; j < length; j++)
        {   
            if(arr[i] == arr[j])    return arr[j];
        }
    }
    return -1;  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:20:45+00:00Added an answer on May 29, 2026 at 7:20 am

    Error number 21 (on MacOS X 10.7.2) is EISDIR: Is a directory.

    The name lotto seems to be a directory, not a file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding Twitter API. I came across something called Parameters and
I came across something weird today, and I was wondering if any of you
I came across something new which i really found hard to understand.. Here is
I just came across something pretty weird to me : when you use the
Came across something like this today, and was wondering if there was an equivalent
I came across something very basic but extremely bewildering today. I needed to convert
Whilst trawling through some old code I came across something similar to the following:
I was reading some Java recently and came across something (an idiom?) new to
So while rewriting some code, I came across something along the lines of: Method
I was perusing the asp.net chart control's sample website, and came across something in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.