我是C域的新手我在编译时遇到大量警告,包括比较指向整数的指针和从没有强制转换的指针生成整数。你能指点我帮忙解决这个问题吗?我附上了我的代码和示例文件。一旦编译为了作为参数运行,您需要包含输入文件名,后跟您喜欢的输出文件名。谢谢!
#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,
int today_month, int all, int n1, int n2, int n3, char *summer_active_temp, char *winter_active_temp, FILE *fpOut)
{
int i;
//determine triggers
//if no active out of season and season is winter
if(summer_active_temp == '0' && today_month == '1')
{
//if enough of winter to do 60% winter 40% non seasonal
if(n3 >= 12)
{
for (i = 0; i < 12; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < 8; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n3; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (20-n3))
{
for (i = 0; i < (20-n3); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
}
//if active out of season and season is winter
else if(summer_active_temp == '1' && today_month == '1')
{
//if enough do 25% summer 50% winter 25% nonseasonal
if(n3 >= 10 && n2 >= 5)
{
for (i = 0; i < 5; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < 10; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= 5)
{
for (i = 0; i < 5; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else if(n3 >= 10 && n2 < 5)
{
for (i = 0; i < n2; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < 10; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (10-n2))
{
for (i = 0; i < (10-n2); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else if(n3 < 10 && n2 >= 5)
{
for (i = 0; i < 5; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < n3; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (15-n3))
{
for (i = 0; i < (15-n3); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else
{
for (i = 0; i < n2; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < n3; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (20-n3-n2))
{
for (i = 0; i < (20-n3-n2); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
}
//if no active out of season and season is summer
else if(winter_active_temp == '0' && today_month == '2')
{
//if enough of summer to do 60% summer 40% non seasonal
if(n2 >= 12)
{
for (i = 0; i < 12; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= 8)
{
for (i = 0; i < 8; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else
{
for (i = 0; i < n2; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (20-n2))
{
for (i = 0; i < (20-n2); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
}
//if active out of season and season is summer
else if(winter_active_temp == '1' && today_month == '2')
{
//if enough do 25% winter 50% summer 25% nonseasonal
if(n2 >= 10 && n3 >= 5)
{
for (i = 0; i < 5; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < 10; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= 5)
{
for (i = 0; i < 5; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else if(n2 >= 10 && n3 < 5)
{
for (i = 0; i < n3; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < 10; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (10-n3))
{
for (i = 0; i < (10-n3); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else if(n2 < 10 && n3 >= 5)
{
for (i = 0; i < 5; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < n2; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (15-n2))
{
for (i = 0; i < (15-n2); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
else
{
for (i = 0; i < n3; ++i) //winter
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
}
for (i = 0; i < n2; ++i) //summer
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,2\n", SywUserIdTemp, IntractnIdBuf2[i], DivNbrBuf2[i], ItemNbrBuf2[i], KsnIdBuf2[i], buddy_cntBuf2[i], summer_active_temp, winter_active_temp);
}
//just in case nonseasonal doesnt have enough to fill in
if(n1 >= (20-n3-n2))
{
for (i = 0; i < (20-n3-n2); ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
else
{
for (i = 0; i < n1; ++i) //nonseasonal
{
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,1\n", SywUserIdTemp, IntractnIdBuf1[i], DivNbrBuf1[i], ItemNbrBuf1[i], KsnIdBuf1[i], buddy_cntBuf1[i], summer_active_temp, winter_active_temp);
}
}
}
}
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
int today_month = 0;
time_t result = time(NULL);
struct tm* today = (localtime(&result));
char month_str[3];
strftime(month_str, sizeof(month_str), "%m", today);
if(*month_str < "03" || *month_str > "08"){
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(SywUserIdTemp == SywUserId)
{
if(table_type == 1)
{
IntractnIdBuf1[n1] = IntractnId;
DivNbrBuf1[n1] = DivNbr;
ItemNbrBuf1[n1] = ItemNbr;
KsnIdBuf1[n1] = KsnId;
buddy_cntBuf1[n1++] = buddy_cnt;
}
else if(table_type == 2)
{
IntractnIdBuf2[n2] = IntractnId;
DivNbrBuf2[n2] = DivNbr;
ItemNbrBuf2[n2] = ItemNbr;
KsnIdBuf2[n2] = KsnId;
buddy_cntBuf2[n2++] = buddy_cnt;
}
else //table_type == 3
{
IntractnIdBuf3[n3] = IntractnId;
DivNbrBuf3[n3] = DivNbr;
ItemNbrBuf3[n3] = ItemNbr;
KsnIdBuf3[n3] = KsnId;
buddy_cntBuf3[n3++] = buddy_cnt;
}
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(SywUserIdTemp != 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(table_type == 1)
{
IntractnIdBuf1[n1] = IntractnId;
DivNbrBuf1[n1] = DivNbr;
ItemNbrBuf1[n1] = ItemNbr;
KsnIdBuf1[n1] = KsnId;
buddy_cntBuf1[n1++] = buddy_cnt;
}
else if(table_type == 2)
{
IntractnIdBuf2[n2] = IntractnId;
DivNbrBuf2[n2] = DivNbr;
ItemNbrBuf2[n2] = ItemNbr;
KsnIdBuf2[n2] = KsnId;
buddy_cntBuf2[n2++] = buddy_cnt;
}
else //table_type == 3
{
IntractnIdBuf3[n3] = IntractnId;
DivNbrBuf3[n3] = DivNbr;
ItemNbrBuf3[n3] = ItemNbr;
KsnIdBuf3[n3] = KsnId;
buddy_cntBuf3[n3++] = buddy_cnt;
}
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);
}
test_data.txt
1,1,1,-276551,7,63062,0,1.993,0,0,
1,1,10,24315147,54,41796,0,1.934,0,0,
1,1,11,25562371,2,40396,3747849,1.934,0,0,
1,1,12,-948793,2,2820,0,1.919,0,0,
1,1,13,4272725,44,20243,0,1.911,0,0,
1,1,14,2917566,44,71641,0,1.900,0,0,
1,1,15,24655338,54,71593,0,1.898,0,0,
1,1,16,22365342,44,67862,0,1.894,0,0,
1,1,17,12690269,44,14216,0,1.886,0,0,
1,1,18,2920093,44,93074,0,1.875,0,0,
1,1,19,8569801,2,40396,0,1.868,0,0,
1,1,2,-273684,7,63204,0,1.984,0,0,
1,1,20,10171246,88,2379,0,1.859,0,0,
1,1,3,1617035,44,72854,0,1.977,0,0,
1,1,4,12690127,44,14602,0,1.973,0,0,
1,1,5,13064870,44,13666,0,1.966,0,0,
1,1,6,1616493,44,34869,0,1.966,0,0,
1,1,7,1617032,44,72854,0,1.956,0,0,
1,1,8,1616460,44,23337,0,1.950,0,0,
1,1,9,24655107,2,94350,0,1.948,0,0,
答案 0 :(得分:0)
您正在尝试将指针打印为整数。指针的正确格式说明符是"%p"
,而不是"%lu"
。
答案 1 :(得分:0)
fprintf(fpOut, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,3\n", SywUserIdTemp, IntractnIdBuf3[i], DivNbrBuf3[i], ItemNbrBuf3[i], KsnIdBuf3[i], buddy_cntBuf3[i], summer_active_temp, winter_active_temp);
%lu表示SywUserIdTemp应该是一个整数,但是你传递了一个C字符串,一个char指针。您希望使用%s而不是5lu作为该参数,假设它是NUL终止的C字符串。
答案 2 :(得分:0)
这一行
if(* month_str&lt;“03”|| * month_str&gt;“08”){
有三个问题:
表达式*month_str
为您提供month_str
中的第一个字符,表达式的类型为char
,而不是char *
}。这是至少一个“指向整数指针的比较”错误的来源,因为......
在此上下文中,字符串文字"03"
和"08"
最终将具有类型char *
,并将评估每个字符串的第一个元素的地址,但更大的问题是......
您无法使用关系运算符(<
,>
,==
等来比较字符串值。您必须使用strcmp
库函数。
该行应为
if ( strcmp( month_str, "03" ) < 0 || strcmp( month_str, "08" ) > 0 )
{
...
}
查看您方便的C参考手册,了解strcmp
的返回值的说明。