这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int isPresent(char *array[], char *string, int dimension) {
for (int i=0; i<dimension; i++) {
if (strcmp(array[i], string) != 0) {
continue;
} else {
return 1;
}
}
return 0;
}
int main(int argc, char *argv[]) {
int dim = 0;
char **without_duplicates = malloc(dim * sizeof(char *));
for (int i=1; i<argc; i++) {
if (!isPresent(without_duplicates, argv[i], dim)) {
realloc(without_duplicates, (dim + 1) * sizeof(char *));
without_duplicates[dim] = malloc((strlen(argv[i]) + 1) * sizeof(char)); …Run Code Online (Sandbox Code Playgroud)