这是我的代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define BUF_LEN 1024
int SendOut(char *SywUserIdTemp, char *IntractnIdBuf1, char *IntractnIdBuf2, char *IntractnIdBuf3,
char *DivNbrBuf1, char *DivNbrBuf2, char *DivNbrBuf3,
char *ItemNbrBuf1, char *ItemNbrBuf2, char *ItemNbrBuf3,
char *KsnIdBuf1, char *KsnIdBuf2, char *KsnIdBuf3,
char *buddy_cntBuf1, char *buddy_cntBuf2, char *buddy_cntBuf3,
char *today_month, int all, int n1, int n2, int n3, char *summer_active_temp, char *winter_active_temp, FILE *fpOut)
{
//function logic
return(0);
}
int main(int argn, char* argv[])
{
//initialize variables
int i, all;
//char SywUserId, IntractnId, DivNbr, ItemNbr, KsnId, buddy_cnt, cnt_rank, table_type, summer_active, summer_active_temp, winter_active, winter_active_temp, SywUserIdTemp;
char *SywUserId, *IntractnId, *DivNbr, *ItemNbr, *KsnId, *buddy_cnt, *cnt_rank, *table_type, *summer_active, *winter_active, *summer_active_temp, *winter_active_temp, *SywUserIdTemp;
FILE *fpIn, *fpOut;
char buf[BUF_LEN];
char *IntractnIdBuf1[BUF_LEN], *DivNbrBuf1[BUF_LEN], *ItemNbrBuf1[BUF_LEN], *KsnIdBuf1[BUF_LEN], *buddy_cntBuf1[BUF_LEN];
char *IntractnIdBuf2[BUF_LEN], *DivNbrBuf2[BUF_LEN], *ItemNbrBuf2[BUF_LEN], *KsnIdBuf2[BUF_LEN], *buddy_cntBuf2[BUF_LEN];
char *IntractnIdBuf3[BUF_LEN], *DivNbrBuf3[BUF_LEN], *ItemNbrBuf3[BUF_LEN], *KsnIdBuf3[BUF_LEN], *buddy_cntBuf3[BUF_LEN];
int n1=0, n2=0, n3=0;
int nRow=0, iCount=0;
//determine season
char *today_month;
time_t result = time(NULL);
struct tm* today = (localtime(&result));
char month_str[3];
strftime(month_str, sizeof(month_str), "%m", today);
if ( strcmp( month_str, "03" ) < 0 || strcmp( month_str, "08" ) > 0 ){
today_month = "1"; //winter
}
else{
today_month = "2"; //summer
}
//if input does not have 3 arguments terminate
if(argn != 3) {
printf("Usage: %s input_file output_file\n", argv[0]);
return(-1);
}
//check for input file
fpIn = fopen(argv[1], "r");
if(fpIn == NULL) {
printf("Error: no input file");
}
//check for output files
fpOut = fopen(argv[2], "w");
if(fpOut == NULL) {
printf("Error: no output file");
}
// Skip the first row.
//fgets(buf, BUF_LEN, fpIn);
// Process the data.
fgets(buf, BUF_LEN, fpIn);
SywUserIdTemp = "0";
winter_active_temp = "0";
summer_active_temp = "0";
n1 = 0;
n2 = 0;
n3 = 0;
all = 0;
while(!feof(fpIn)) {
if(strlen(buf) < 2) break;
// Remove CR or LF at the tail.
i=strlen(buf)-1; while(i > 0 && buf[i] <= ' ') buf[i--] = '\0';
SywUserId = strtok(buf, ",");
table_type = strtok(NULL, ",");
cnt_rank = strtok(NULL, ",");
IntractnId = strtok(NULL, ",");
DivNbr = strtok(NULL, ",");
ItemNbr = strtok(NULL, ",");
KsnId = strtok(NULL, ",");
buddy_cnt = strtok(NULL, ",");
summer_active = strtok(NULL, ",");
winter_active = strtok(NULL, ",");
printf("%s:%s:%s:%s:%s:%s:%s:%s:%s:%s\n", SywUserId, table_type, cnt_rank, IntractnId, DivNbr, ItemNbr, KsnId, buddy_cnt, summer_active, winter_active);
//if it is the same member the ksn number is saved in a buffer to create pairs from
if( strcmp(SywUserIdTemp, SywUserId) == 0 )
{
if( strcmp(table_type, "1") == 0 )
{
//IntractnIdBuf1[n1] = IntractnId;
//DivNbrBuf1[n1] = DivNbr;
//ItemNbrBuf1[n1] = ItemNbr;
//KsnIdBuf1[n1] = KsnId;
//buddy_cntBuf1[n1++] = buddy_cnt;
strncpy(IntractnIdBuf1[n1], IntractnId, BUF_LEN - 1);
strncpy(DivNbrBuf1[n1], DivNbr, BUF_LEN - 1);
strncpy(ItemNbrBuf1[n1], ItemNbr, BUF_LEN - 1);
strncpy(KsnIdBuf1[n1], KsnId, BUF_LEN - 1);
strncpy(buddy_cntBuf1[n1++], buddy_cnt, BUF_LEN - 1);
}
else if(strcmp(table_type, "2") == 0 )
{
//IntractnIdBuf2[n2] = IntractnId;
//DivNbrBuf2[n2] = DivNbr;
//ItemNbrBuf2[n2] = ItemNbr;
//KsnIdBuf2[n2] = KsnId;
//buddy_cntBuf2[n2++] = buddy_cnt;
strncpy(IntractnIdBuf2[n2], IntractnId, BUF_LEN - 1);
strncpy(DivNbrBuf2[n2], DivNbr, BUF_LEN - 1);
strncpy(ItemNbrBuf2[n2], ItemNbr, BUF_LEN - 1);
strncpy(KsnIdBuf2[n2], KsnId, BUF_LEN - 1);
strncpy(buddy_cntBuf2[n2++], buddy_cnt, BUF_LEN - 1);
}
else //table_type == 3
{
//IntractnIdBuf3[n3] = IntractnId;
//DivNbrBuf3[n3] = DivNbr;
//ItemNbrBuf3[n3] = ItemNbr;
//KsnIdBuf3[n3] = KsnId;
//buddy_cntBuf3[n3++] = buddy_cnt;
strncpy(IntractnIdBuf3[n3], IntractnId, BUF_LEN - 1);
strncpy(DivNbrBuf3[n3], DivNbr, BUF_LEN - 1);
strncpy(ItemNbrBuf3[n3], ItemNbr, BUF_LEN - 1);
strncpy(KsnIdBuf3[n3], KsnId, BUF_LEN - 1);
strncpy(buddy_cntBuf3[n3++], buddy_cnt, BUF_LEN - 1);
}
all++;
}
//else all the combos are created and written to the output file
//the new mbrId is copied to the tempMbrId
//the nKsn is reset to 0 and the new ksnId is saved in the buffer
else
{
if(strcmp(table_type, "0") > 0 || strcmp(table_type, "0") < 0 )
{
SendOut(SywUserIdTemp, IntractnIdBuf1, IntractnIdBuf2, IntractnIdBuf3,
DivNbrBuf1, DivNbrBuf2, DivNbrBuf3,
ItemNbrBuf1, ItemNbrBuf2, ItemNbrBuf3,
KsnIdBuf1, KsnIdBuf2, KsnIdBuf3,
buddy_cntBuf1, buddy_cntBuf2, buddy_cntBuf3,
today_month, all, n1, n2, n3, summer_active_temp, winter_active_temp, fpOut);
}
//reset info
SywUserIdTemp = SywUserId;
summer_active_temp = summer_active;
winter_active_temp = winter_active;
n1 = 0;
n2 = 0;
n3 = 0;
all = 0;
if(strcmp(table_type, "1") == 0 )
{
//IntractnIdBuf1[n1] = IntractnId;
//DivNbrBuf1[n1] = DivNbr;
//ItemNbrBuf1[n1] = ItemNbr;
//KsnIdBuf1[n1] = KsnId;
//buddy_cntBuf1[n1++] = buddy_cnt;
strncpy(IntractnIdBuf1[n1], IntractnId, BUF_LEN - 1);
strncpy(DivNbrBuf1[n1], DivNbr, BUF_LEN - 1);
strncpy(ItemNbrBuf1[n1], ItemNbr, BUF_LEN - 1);
strncpy(KsnIdBuf1[n1], KsnId, BUF_LEN - 1);
strncpy(buddy_cntBuf1[n1++], buddy_cnt, BUF_LEN - 1);
}
else if(strcmp(table_type, "2") == 0)
{
//IntractnIdBuf2[n2] = IntractnId;
//DivNbrBuf2[n2] = DivNbr;
//ItemNbrBuf2[n2] = ItemNbr;
//KsnIdBuf2[n2] = KsnId;
//buddy_cntBuf2[n2++] = buddy_cnt;
strncpy(IntractnIdBuf2[n2], IntractnId, BUF_LEN - 1);
strncpy(DivNbrBuf2[n2], DivNbr, BUF_LEN - 1);
strncpy(ItemNbrBuf2[n2], ItemNbr, BUF_LEN - 1);
strncpy(KsnIdBuf2[n2], KsnId, BUF_LEN - 1);
strncpy(buddy_cntBuf2[n2++], buddy_cnt, BUF_LEN - 1);
}
else //table_type == 3
{
//IntractnIdBuf3[n3] = IntractnId;
//DivNbrBuf3[n3] = DivNbr;
//ItemNbrBuf3[n3] = ItemNbr;
//KsnIdBuf3[n3] = KsnId;
//buddy_cntBuf3[n3++] = buddy_cnt;
strncpy(IntractnIdBuf3[n3], IntractnId, BUF_LEN - 1);
strncpy(DivNbrBuf3[n3], DivNbr, BUF_LEN - 1);
strncpy(ItemNbrBuf3[n3], ItemNbr, BUF_LEN - 1);
strncpy(KsnIdBuf3[n3], KsnId, BUF_LEN - 1);
strncpy(buddy_cntBuf3[n3++], buddy_cnt, BUF_LEN - 1);
}
all++;
//printf("nKsn=%d", nKsn);
}
// Show the progress.
nRow++;
if( iCount < 999 ) {
iCount++;
} else {
printf("%d\n", nRow);
iCount = 0;
}
fgets(buf, BUF_LEN, fpIn);
}
SendOut(SywUserIdTemp, IntractnIdBuf1, IntractnIdBuf2, IntractnIdBuf3,
DivNbrBuf1, DivNbrBuf2, DivNbrBuf3,
ItemNbrBuf1, ItemNbrBuf2, ItemNbrBuf3,
KsnIdBuf1, KsnIdBuf2, KsnIdBuf3,
buddy_cntBuf1, buddy_cntBuf2, buddy_cntBuf3,
today_month, all, n1, n2, n3, summer_active_temp, winter_active_temp, fpOut);
//close files when done
fclose(fpIn);
fclose(fpOut);
//exit program
return(0);
}
以下是错误消息:
warning: passing argument 2 of âSendOutâ from incompatible pointer type
warning: passing argument 3 of âSendOutâ from incompatible pointer type
warning: passing argument 4 of âSendOutâ from incompatible pointer type
warning: passing argument 5 of âSendOutâ from incompatible pointer type
warning: passing argument 6 of âSendOutâ from incompatible pointer type
warning: passing argument 7 of âSendOutâ from incompatible pointer type
warning: passing argument 8 of âSendOutâ from incompatible pointer type
warning: passing argument 9 of âSendOutâ from incompatible pointer type
warning: passing argument 10 of âSendOutâ from incompatible pointer type
warning: passing argument 11 of âSendOutâ from incompatible pointer type
warning: passing argument 12 of âSendOutâ from incompatible pointer type
warning: passing argument 13 of âSendOutâ from incompatible pointer type
warning: passing argument 14 of âSendOutâ from incompatible pointer type
warning: passing argument 15 of âSendOutâ from incompatible pointer type
warning: passing argument 16 of âSendOutâ from incompatible pointer type
有人可以解释为什么指针类型不兼容。我知道每次调用程序顶部的函数时,我都会收到同样的警告。感谢。
答案 0 :(得分:1)
参数声明为char*
。您正在通过char**
。因此警告。例如,对于第二个参数,您传递IntractnIdBuf1
,其声明如下:
char *IntractnIdBuf1[BUF_LEN]
所以IntractnIdBuf1
是一个衰变为char**
类型指针的数组。
我没有比这更详细地研究你的代码。但是您可能需要将声明更改为:
char IntractnIdBuf1[BUF_LEN]
等等。
答案 1 :(得分:0)
这些:
char *IntractnIdBuf1[BUF_LEN], *DivNbrBuf1[BUF_LEN], *ItemNbrBuf1[BUF_LEN], *KsnIdBuf1[BUF_LEN], *buddy_cntBuf1[BUF_LEN];
char *IntractnIdBuf2[BUF_LEN], *DivNbrBuf2[BUF_LEN], *ItemNbrBuf2[BUF_LEN], *KsnIdBuf2[BUF_LEN], *buddy_cntBuf2[BUF_LEN];
char *IntractnIdBuf3[BUF_LEN], *DivNbrBuf3[BUF_LEN], *ItemNbrBuf3[BUF_LEN], *KsnIdBuf3[BUF_LEN], *buddy_cntBuf3[BUF_LEN];
是char *的数组。因此,它们在技术上是特征。函数参数需要char * s。