Skip to content

Instantly share code, notes, and snippets.

@nickdotht
Last active March 18, 2017 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdotht/0e21956f03ca76b83c58dcbe772491f4 to your computer and use it in GitHub Desktop.
Save nickdotht/0e21956f03ca76b83c58dcbe772491f4 to your computer and use it in GitHub Desktop.
arr_find.c
#include <stdio.h>
#include <stdlib.h>
int main(int ac, char **av)
{
int t;
int n;
int *arr;
int i;
int j;
int target;
if (!ac)
return (0);
(void)av;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
arr = (int *)malloc(sizeof(int));
i = 0;
while (n--)
scanf("%d", &arr[i++]);
scanf("%d", &target);
j = 0;
while (arr[j++] != '\0' && arr[j] != target);
printf("%d\n", arr[j] != '\0' ? j : -1);
}
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment