removing a duplicate entry

This is a discussion on removing a duplicate entry within the C Programming forums, part of the General Programming Boards category; Hello everyone, I am trying to remove a duplicate entry. My problem is in the two if statements following the ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    178

    removing a duplicate entry

    Hello everyone,
    I am trying to remove a duplicate entry. My problem is in the two if statements following the for loop and I for some reason cannot figure it out. I have one entry in a file that has the same department name AND course number. I am trying to get one of those removed as my instructions are to list only distinct dept/course number. My question is can someone show me what my error is and how I might go about fixing it?
    Code:
    #include "classes.h"
    
    int main(void)
    {
        int switchInput;
        int i = 0;
        int tempCourse = 0, tempCourse1 = 0;
        char caseOneInput[5];
        FILE *filePointer;
        sched_record data[MAX_RECORD];
    
        filePointer = fopen (BINFILE, "rb");
        if (filePointer == NULL) {
            printf("**Can't open file**");
            printf("**Check file permissions of file path**\n");
            exit(1);
        }
    
        printf("Enter your choice: ");
        scanf("%d", &switchInput);
    
        switch(switchInput)
        {
            case 1:
    
                fread(data, sizeof(sched_record), MAX_RECORD, filePointer);
                fclose(filePointer);
                printf("Enter Dept Name: ");
                scanf("%s", caseOneInput);
                qsort(data, MAX_RECORD, sizeof(sched_record), sortFunction);
                for (i=0; i<MAX_RECORD; i++){
                    if (!strcmp(caseOneInput, data[i].Dept)){
                        if(tempCourse != data[i].course);{
                        printf("\n%s %d", data[i].Dept, data[i].course);
                        tempCourse = data[i].course;
                        }
    
                    }
                }
        }
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,830
    I would look carefully towards the end of line 33....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    I don't know if this is your problem or not, but the phrase:

    Code:
    !strcmp
    is nonsensical. Read up on strcmp and what it returns.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Quote Originally Posted by Salem View Post
    I would look carefully towards the end of line 33....
    Dang, I thought my logic was correct. Thanks alot!

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Quote Originally Posted by ledow View Post
    I don't know if this is your problem or not, but the phrase:

    Code:
    !strcmp
    is nonsensical. Read up on strcmp and what it returns.
    How about this?
    Code:
    if (strcmp(caseOneInput, data[i].Dept)==0){

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Removing duplicate values from std::list
    By Phenom in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2010, 01:59 PM
  2. Computation Loop and duplicate entry error
    By digitaldan in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2010, 02:19 AM
  3. Removing duplicate items from vector
    By 7heavens in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2010, 05:38 AM
  4. how to avoid duplicate entry to a list/array?
    By janetsmith in forum C Programming
    Replies: 5
    Last Post: 12-17-2006, 09:32 AM
  5. Database entry - avoiding duplicate records
    By ChadJohnson in forum Tech Board
    Replies: 2
    Last Post: 02-04-2006, 12:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21