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;
}
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;
}
With a declaration of int *array_diff you will need to return a dynamically allocated array as opposed to one only local to the scope of the function. To make the expectations more clear, I have added some comments to the solution set-up, one of which refers to setting *z as the array length as opposed to z. Use malloc to define your return, and the test suite will free the memory.
Please, mark your post as having spoiler content next time, also, check how to use markdown formatting when posting code here, there is a link in the post below.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
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];
}
}
}
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;
}
#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];
}
}
}
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.
With a declaration of
int *array_diff
you will need to return a dynamically allocated array as opposed to one only local to the scope of the function. To make the expectations more clear, I have added some comments to the solution set-up, one of which refers to setting*z
as the array length as opposed toz
. Usemalloc
to define your return, and the test suite willfree
the memory.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 :(
Please, mark your post as having spoiler content next time, also, check how to use markdown formatting when posting code here, there is a link in the post below.
thank you founded
This comment is hidden because it contains spoiler information about the solution
None
to the caller (https://docs.codewars.com/training/troubleshooting#expected-the-same)This comment is hidden because it contains spoiler information about the solution