I'm trying to make the uniq command from linux using C coding
<p>I am trying to make the uniq command using C coding, which will remove and duplicate lines as part of a homework assignment. I am 1 year into java and literally jsut started C programming. it's overwhelming. I decided the basic thing to do was make a program that takes in a file, and prints out its contents. Next i decided to make the program tell how many lines there are. The problem i have now is to make each line display its respective line. in my code, each line will display its line and the one before this. After this, i need to figure out how to make my program scan each line for duplicated and delete them. Any help would do, thanks!</p>

<pre><code>#include &lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;ctype.h&gt;

void process_file(FILE* f);
char str [1000];
char c;
int r=0;
int line;
char temp;

int main(int argc, char* argv[]){
    process_file(argv[1]);
    return 0;
}

void process_file(FILE* f){
    FILE *fp = fopen(f,"r");
    if ( fp == NULL){
        printf("Error: No such file\n");
        exit(1);
    }
    while( (c = fgetc(fp)) != EOF){

        str[r] = c;
        r++;
        if (c =='\n'){
            line++;
            printf("new line %d\n", line);
            printf("%s\n", str);
        }
    }
    fclose(fp);
    return;
}
</code></pre>