Can someone make some sense out of this code for me. I understand how the switch works but they lost me on the for loop using *fld[NUMFLD]. NUMFLD was defined as 10 and rec is a char array (rec[1000]) containing a line copied from a file. FLDSEP was defined as "|". I posted question on the pointer and it makes some sense now thanks to everyone who helped answer my questions. Now I am confused again. I can probably get thru id I knew what was happening during the for loop. Thanks for any assistance.
Code:
920 int fldcnt = 0;
921 char *fld[NUMFLD]; - *fld[10]
922 int error_flag = 0;
923 char tmprec[MAXRECLEN]; - tmprec[1000]
924 int index = 0;
925
926 sprintf(jnl.mesg,"%s",rec);
927 log_it(log_file,jnl);
928
929 strcpy(tmprec,rec); - copy the line into tmprec[1000]
930 bzero(&fld,NUMFLD);
931 for (fld[fldcnt] = strtok(tmprec,FLDSEP);
932 fld[fldcnt] != NULL;
933 fld[++fldcnt] = strtok(NULL,FLDSEP))
934 {
935 strip_trailing_spaces(fld[fldcnt]);
936
937 switch(fldcnt)
938 {
939 case 0: /* bol */
940 pgi_ack_file.bol = atoi(fld[fldcnt]);
941 break;
942 case 1: /* delivery */
943 strcpy(pgi_ack_file.delivery,fld[fldcnt]);
944 break;
945 case 2: /* delivery_item */
946 pgi_ack_file.delivery_item = atoi(fld[fldcnt]);
947 break;
948 case 3: /* mfg_std */
949 pgi_ack_file.mfg_std = atoi(fld[fldcnt]);
950 break;
951 case 4: /* num_skids */
952 pgi_ack_file.num_skids = atoi(fld[fldcnt]);
953 break;
954 case 5: /* skid_num */
955 pgi_ack_file.skid_num = atoi(fld[fldcnt]);
956 break;
957 case 6: /* unit */
958 strcpy(pgi_ack_file.unit_txt,fld[fldcnt]);
959 break;
960 case 7: /* gross weight */
961 pgi_ack_file.skid_gross_wght_lbs = atof(fld[fldcnt]);
962 break;
963 case 8: /* net weight */
964 pgi_ack_file.skid_net_wght_lbs = atof(fld[fldcnt]);
965 break;
966 case 9: /* storage location */
967 pgi_ack_file.storage_location = atoi(fld[fldcnt]);
968 break;
969 default:
970 strcpy(jnl.mesg,"Too many fields in record");
971 log_it(log_file,jnl);
972 sprintf(jnl.mesg,"Bad fldcnt %d. should be %d",fldcnt,NUMFLD);
973 log_it(log_file,jnl);
974 error_flag = 1;
975 break;
976 }
977
978 if (error_flag == 1) return (IMCS_DB_FATAL);
979 }
980
981 if (fldcnt != NUMFLD)
982 {
983 strcpy(jnl.mesg,"Too few fields in record");
984 log_it(log_file,jnl);
985 sprintf(jnl.mesg,"Bad fldcnt %d. should be %d",fldcnt,NUMFLD);
986 log_it(log_file,jnl);
987 error_flag = 1;
988 return (IMCS_DB_FATAL);
989 }