Hi guys.
I need some help.
I need to delete DUPLICATED strings/chars from an input file.
Code:
// C Code
#include <assert.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tgmath.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
void strings_fprintfln(FILE *f, char **s, int n, const char *fmt)
{
strings_fprintf(f, s, n, fmt);
fprintf(f, "\n");
}
void strings_printfln(char **s, int n, const char *fmt)
{
strings_fprintfln(stdout, s, n, fmt);
}
char *str_dup(const char *s)
{
char *result = (char *) malloc(strlen(s) + 1);
strcpy(result, s);
return result;
}
int strings_readwords(FILE *f, char **a)
{
int result = 0;
char word[MAX_LINE_LENGTH];
while (fscanf(f, "%s", word) != EOF)
a[result++] = str_dup(word);
return result;
}
int strings_getwords(char **a)
{
return strings_readwords(stdin, a);
}
//Insertion sort
void strings_sort_last(char **a, int n)
{
int i = n-1;
while (i > 0 && strcmp(a[i-1], a[i]) > 0)
{
strings_exchange(a, i-1, i);
i--;
}
}
void strings_isort(char **a, int n)
{
for (int i = 2; i <= n; i++)
strings_sort_last(a, i);
}
void test_stringsisort(void)
{
char *a[1000];
int n;
while ((n = strings_getwords(a)) != 0)
{
strings_isort(a, n);
strings_printfln(a, n, " ");
//removeDuplicates(? , ?); *I NEED THIS!!!*
freopen("CON", "r", stdin);
printf("------\n");
}
}
int main(void)//int argc, string argv[])
{
test_stringsisort();
return 0;
}
With this code i get:
example input.txt:
Code:
Bugh
Aure
Cure
Modew
Cure
Kire
Losa
Modew
Kurds
output:
Code:
Aure
Bugh
Cure
Cure
Kire
Kurds
Losa
Modew
Modew
i need:
Code:
Aure
Bugh
Cure
Kire
Kurds
Losa
Modew
Windows cmd (folder path)>program.exe < input.txt > output.txt
btw, sometimes my output is ------------------