* find.c
 * Computer Science 50
 * Problem Set 3
 * Prompts user for as many as MAX values until EOF is reached,
 * then proceeds to search that "haystack" of values for given needle.
 * Usage: ./find needle
 * where needle is the value to find in a haystack of values

#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>

#include "helpers.h"

// maximum amount of hay
const int MAX = 65536;

int main(int argc, string argv[])
    // ensure proper usage
    if (argc != 2)
        printf("Usage: ./find needle\n");
        return -1;

    // remember needle
    int needle = atoi(argv[1]);

    // fill haystack
    int size;
    int haystack[MAX];
    for (size = 0; size < MAX; size++)
        // wait for hay until EOF
        printf("\nhaystack[%i] = ", size);
        int straw = GetInt();
        if (straw == INT_MAX)

        // add hay to stack
        haystack[size] = straw;

    // sort the haystack
    sort(haystack, size);

    // try to find needle in haystack
    if (search(needle, haystack, size))
        printf("\nFound needle in haystack!\n\n");
        return 0;
        printf("\nDidn't find needle in haystack.\n\n");
        return 1;

error is

clang: error: cannot specify -o when generating multiple output files
make: *** [find] Error 1

I see that the file posted is an older version of find.c with the deprecated function GetInt(). It has been replaced with get_int(). Are you using the current version of the pset distribution? Have you run update50 in the IDE recently? Or are you running in another environment? My guess is that these problems are due to outdated code and/or environment.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • my code gives the same error and I typed get_int() – user20606 Nov 29 '17 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .