Deleting a record from struct array

Hello. I want to delete selected records from struct array using cstring reading from files. Here I read my records to stud struct then assign non-deleted to stu struct but its not deleting as desired...strcmp is giving 25

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  
      while(cont=='Y'){
        cout<<"Enter student ID to delete: ";
        cin.ignore();
        cin.getline(id, 15, '\n');
        cout<<stud[0].ID<<endl;
        cout<<strcmp(id,stud[0].ID)<<endl;//---------> 25 not 0 why?
        for(int del=0;del<i;del++){
            if(strcmp(stud[del].ID, id)==0){

                continue;}
            else{
            strcpy(stu[k].ID,stud[del].ID);
            strcpy(stu[k].Name,stud[del].Name);
            strcpy(stu[k].grade,stud[del].grade);
            k++;
        }}
        total=total-1;
       


I did some debugging effort and I found here is the problem..the stud[0].ID and id is not same but why? I am giving in same id and both char array lenght is 15

1
2
3
4
5
6
7
while(cont=='Y'){
        cout<<"Enter student ID to delete: ";
        cin.ignore();
        cin.getline(id, 15);
        cout<<strlen(stud[0].ID)<<" "<<strlen(id)<<endl;///---> lenght 1 is 10
                                                                                  ///---->lenght 2 is 8    
        cout<<strncmp(id,stud[0].ID, 10 )<<endl;
Last edited on
http://blog.codinghorror.com/rubber-duck-problem-solving/
Bob pointed into a corner of the office. "Over there," he said, "is a duck. I want you to ask that duck your question."
r u Chinese?
Topic archived. No new replies allowed.