Part Desig Descr PMI Man Man# Ven
0.01 UF C1-3, 6-8,10-17 Multi EC000100 Pan Ecu Pcc
0.022 UF C20, 22 Multi EC000101 Pan Ecu Pcc
0.047 UF C31 Multi EC000108 Pan Ecu Pcc
...
I tried to created a loop to matching Desig and PMI number together, one line a time and one number a time. For
example, we match c1-3 with PMI EC000100 first, and after that we match 6-8 with PMI EC000100 again until finish the
number under desig column. I was thinking about using
ptr=strchr(buf, ',');
to reading the data. I got right desig number.However, when I tried to use
ptr=strtok(buf, ",");
ptr=strtok('', ",");
to finding PMI number in order to matching with desig. It won't work, because computer can't identify the difference
between tokens and comma between those desig.
I am attaching my program here, and anyone can give me some help, I will very appreciated.
unsigned int read_inventory(FILE* csv) {
char buf[1024], range[256], range2[256],desig[20],pmi[20];
char * ptr;
char * ptr2;
unsigned int x;
unsigned int cntr;
unsigned int startnum, endnum;
memset (inv, 0, sizeof(inv));
cntr = 0;
while (!feof(csv))
{
fgets(buf, sizeof(buf)-1,csv);
ptr=strchr(buf, ',');
if (ptr)
{
ptr++;
strcpy(range, ptr);
ptr = strchr(range, ',');
if (ptr) {
*ptr = 0;
// printf("[%s] ", range);
ptr = range;
ptr2 = range2;
while (*ptr) {
if (*ptr != '"') {
*ptr2 = toupper(*ptr);
ptr2++;
}
ptr++;
}
*ptr2 = 0;
// printf("[%s] ", range2);
/* now range2 has designator range */
x = strspn(range2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
if (x) {
strncpy(desig, range2, x);
desig[x] = 0;
// printf("[%s] ", desig);
strcpy(range, range2+x);
/* now desig has designator name, and range has number range */
ptr=strtok(buf, " ,");
ptr=strtok('', " ,");
ptr=strtok('', " ,");
ptr=strtok('', " ,");
ptr=strtok('', ",");
//printf("[%s] ",ptr);
if (ptr && strlen(ptr)) {
strcpy(pmi, ptr);
if (ptr = strchr(range, '-')) {
startnum = atoi(range);
endnum = atoi(ptr+1);
}
else {
startnum = endnum = atoi(range);
}
for (x=0; x<= (endnum-startnum); x++) {<br>
strcpy(inv[cntr].desig,desig);
inv[cntr].dnum = startnum+x;
strcpy(inv[cntr].pmi_number, pmi);
cntr++;
}
}
}
}
}
}
return 0;
}
--------------------------------------------------------------------------------
It looks like you're new here. If you want to get involved, click one of these buttons!