を機能させる構造のポインタを渡して、私はこれをコンパイルするとき、私は私のstruct
の各部分がのラインに沿って、無効であるというエラーメッセージがたくさん出る:C - トラブル
sort.c:16: request for member 'last' in something not a structure or union
そして、私が使用例のためにだから私は、ポインタを悪用しなければならない
sort.c:18: warning: passing arg 2 of 'strcpy' from incompatible pointer type
...しかし、私はなぜわからない:strcpyの、エラーが読み。
私はDBrecord.h
で定義されたstruct
を持っている:
typedef struct{
int DBrecordID; //ID for each entry, range 0-319
char *last; //student last name
char *first; //student first name
char studentID[8]; //student ID
int age; //student age
class year; //year in school
float gpa; //GPA
int expGradYear; //expected graduation year
}DBrecord;
#include <stdio.h>
#include <string.h>
#include "DBrecord.h"
void bubbleSort(DBrecord **record, int numEntries, int sortChoice) {
int i, j;
char temp[100];
for(i=0; i<numEntries; i++)
for(j = 0; j < numEntries-1; j++)
switch(sortChoice){
//sort by last name
case 1 : if(strcmp(record->last[j], record->last[j+1]) > 0){
//swap the two elements
strcpy(temp, record[j]);
strcpy(record[j], record[j+1]);
strcpy(record[j+1], temp);
}
//sort by first name
case 2 : if(strcmp(record->first[j], record->first[j+1]) > 0){
//swap the two elements
strcpy(temp, record[j]);
strcpy(record[j], record[j+1]);
strcpy(record[j+1], temp);
}
//sort by student ID
case 3 : if(atoi(record->studentID[j]) > atoi(record->studentID[j+1])){
//swap the two elements
temp = record[j];
record[j] = record[j+1];
record[j+1] = temp;
}
//sort by age
case 4 : if(atoi(record->age[j]) > atoi(record->age[j+1])){
//swap the two elements
temp = record[j];
record[j] = record[j+1];
record[j+1] = temp;
}
//sort by class
case 5 : if(record->class[j] > record->class[j+1]){
//swap the two elements
temp = record[j];
record[j] = record[j+1];
record[j+1] = temp;
}
//sort by gpa
case 6 : if(atoi(record->gpa[j]) > atoi(record->gpa[j+1])){
//swap the two elements
temp = record[j];
record[j] = record[j+1];
record[j+1] = temp;
}
//sort by expected graduation year
case 7 : if(atoi(record->expGradYear[j]) > atoi(record->expGradYear[j+1])){
//swap the two elements
temp = record[j];
record[j] = record[j+1];
record[j+1] = temp;
}
default : break;
}
私はそれが私の言いたいことだと信じています...おかげで、今、お試しください。 – manalishi