Ad
  • Custom User Avatar

    help with this is become frustating

    #include <stdlib.h>

    int getIndex( const int arr[], int el, size_t n);

    int *array_diff(const int *arr1, size_t n1, const int *arr2, size_t n2, size_t *z) {
    if(n1 == 0){
    return 0;
    }else {
    int tmp[] = {0};
    int index = 0;
    for (size_t t=0;t<n1;t++){
    tmp[t] = arr1[t];
    }

    for (size_t i=0;i<n2;i++){
      while (index != -1){
        index = getIndex(tmp, arr2[i], n1);
        for (size_t k=index;k<n1;k++){
          tmp[k] = tmp[k+1];
        }
      }
      index = 0;
    }
    z = (size_t *)(sizeof(tmp) / sizeof(tmp[0]));
    return (int *)(sizeof(tmp) / sizeof(tmp[0]));
    

    }
    }

    int getIndex( const int arr[], int el, size_t n){
    int h = -1;
    for (size_t i=0;i<n;i++){
    if (arr[i] == el){
    h = i;
    break;
    }
    }
    if (h != -1){
    return h;
    }
    else return -1;
    }

  • Custom User Avatar

    #include <stdlib.h>

    int getIndex( const int arr[], int el, size_t n);

    int *array_diff(const int *arr1, size_t n1, const int *arr2, size_t n2, size_t *z) {
    if(n1 == 0){
    return 0;
    }else {
    int tmp[] = {0};
    int index = 0;
    for (size_t t=0;t<n1;t++){
    tmp[t] = arr1[t];
    }

    for (size_t i=0;i<n2;i++){
      while (index != -1){
        index = getIndex(tmp, arr2[i], n1);
        for (size_t k=index;k<n1;k++){
          tmp[k] = tmp[k+1];
        }
      }
      index = 0;
    }
    z = (size_t *)(sizeof(tmp) / sizeof(tmp[0]));
    return (int *)(sizeof(tmp) / sizeof(tmp[0]));
    

    }
    }

    int getIndex( const int arr[], int el, size_t n){
    int h = -1;
    for (size_t i=0;i<n;i++){
    if (arr[i] == el){
    h = i;
    break;
    }
    }
    if (h != -1){
    return h;
    }
    else return -1;
    }

    help with this, is become frustating.

  • Custom User Avatar

    I'm new here and beginner too, I've done the same function in python and javascript but in c language problem with variable types :(

  • Custom User Avatar

    thank you founded

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution