Skip to content

Instantly share code, notes, and snippets.

@shinymimiq
Created July 15, 2014 14:13
Show Gist options
  • Save shinymimiq/34dc03600e6b905de73a to your computer and use it in GitHub Desktop.
Save shinymimiq/34dc03600e6b905de73a to your computer and use it in GitHub Desktop.
Simple C function to remove a element in the array
#include <stdio.h>
void removeelement(int,int,int*);
int main(int argc, char *argv[]) {
int num = 20;
int list[num];
for (int i = 0; i < num ; i++) {
list[i]=i;
}
removeelement(5,num,list);
for (int i=0; i<num-1; i++) {
printf("%d, ",list[i]);
}
}
void removeelement(int number, int num, int* list){
int i = 0;
for (; i < num; i++) {
if(number == list[i]){
break;
}
}
for (; i < num-1; i++) {
list[i]=list[i+1];
}
num--;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment