Hello, am working on a program for the U.S. Department of Labor. I am working on two programs for the state of Oregon, and the program that reads data and displays on a screen is working correctly. The code reads tax rates for a specific tax schedule and puts htam in a one-dimensional array. The code in the screen program follows:
`for (iLine = 0, j = 1; iLine <= 9; ++iLine, j++)
{
if ((iLine * 9) < knri)
{
strcpy(tempString, "");
for (mm = 0; mm < 5; mm++)
{
strncat(tempString, &range[k][mm], 1);
}
mvwaddstr(win,3,xx,tempString);
k = k + 1;
xx = xx + 11;
}
mvwprintw(win,yy,3,"%d ",j);
yy++;
ilast=9;
if(iLine==jmax) ilast=imax;
/* Read the next line into ppcard, an array at least 81 characters in size. */
fgets(ppcard, 82, upd);
iOffset = 0;
for (iField = 0, i = 0; iField < 9; ++iField, i++)
{
if ((iLine * 9) + iField > knri)
{
break;
}
else
{
if (sscanf(ppcard + iOffset, "%lf%n", &solvsurchgrt[(iLine * 9) + iField], &iNewOffset) < 1)
{
/* stop reading this line and try the next. */
break;
}
else
{
gg = x;
snprintf(surchgrtString, 6, "%5.3f", solvsurchgrt[jj-1]);
for (kk = 0; kk < 5; kk++)
{
screenChar = surchgrtString[kk];
mvwaddch(win,y,x,screenChar);
x = x + 1;
}
x = gg;
/* Add on the length of the last field so that we start reading the next number after that */
iOffset += iNewOffset;
jj++;
y++;
if ( y > 14 )
{
y = 5;
x +=11;
}
}
}
}
} /* end READ tax rates */`
The variables that you see in the above code are already declared earlier in the program. This reads in the data without a problem.
The code in the server program for Oregon reads the same data into a two-dimensional array. The reason for the difference is that the
screen program is reading in tax rates for one tax schedule at a time, where the server program reads in all of the tax rates, for all
tax schedules, and uses the second subscript to reference the calculated correct schedule and its associated rates later in the code.
The code in the server program to read in the tax rates follows:
`for (l=1; l<=15; l++)
{
iFields = 0;
for (i=1; i<=9; i++)
{
fgets(str, 82, fip);
printf("DEBUG4: the line of tax rates read in is %s\n", str);
iOffset = 0;
printf("DEBUG5: iFields is %d\n", iFields);
for (m=1; m<=9; m++)
{
sscanf(str+iOffset, "%5.3f", &xrate[(m-1)+iFields][l-1]);
DEBUG6: iOffset is %d, xrate is %5.3f, subscript is %d\n", iOffset, xrate[(m-1)+iFields][l-1], (m-1)+iFields);
iOffset += 6;
}
iFields += 9;
}
}`
Once again, the variables used in the above code are declared earlier in the program. The server code above produces the following debug statements:
DEBUG4: the line of tax rates read in is 0.500 0.60 0 00 800 .900 1.000 1.10 0 00 300 0 0
DEBUG5: iFields is 0
DEBUG6: iOffset is 0, xrate is 0.000, subscript is 0
DEBUG6: iOffset is 6, xrate is 0.000, subscript is 1
DEBUG6: iOffset is 12, xrate is 0.000, subscript is 2
DEBUG6: iOffset is 18, xrate is 0.000, subscript is 3
DEBUG6: iOffset is 24, xrate is 0.000, subscript is 4
DEBUG6: iOffset is 30, xrate is 0.000, subscript is 5
DEBUG6: iOffset is 36, xrate is 0.000, subscript is 6
DEBUG6: iOffset is 42, xrate is 0.000, subscript is 7
DEBUG6: iOffset is 48, xrate is 0.000, subscript is 8
DEBUG4: the line of tax rates read in is 0 0 0
DEBUG5: iFields is 9
DEBUG6: iOffset is 0, xrate is 0.000, subscript is 9
DEBUG6: iOffset is 6, xrate is 0.000, subscript is 10
DEBUG6: iOffset is 12, xrate is 0.000, subscript is 11
DEBUG6: iOffset is 18, xrate is 0.000, subscript is 12
DEBUG6: iOffset is 24, xrate is 0.000, subscript is 13
DEBUG6: iOffset is 30, xrate is 0.000, subscript is 14
DEBUG6: iOffset is 36, xrate is 0.000, subscript is 15
DEBUG6: iOffset is 42, xrate is 0.000, subscript is 16
DEBUG6: iOffset is 48, xrate is 0.000, subscript is 17
DEBUG4: the line of tax rates read in is 1.400 1.50 0 00 700 .800 1.900 2.00 0 00 200 0 0
DEBUG5: iFields is 18
DEBUG6: iOffset is 0, xrate is 0.000, subscript is 18
DEBUG6: iOffset is 6, xrate is 0.000, subscript is 19
DEBUG6: iOffset is 12, xrate is 0.000, subscript is 20
DEBUG6: iOffset is 18, xrate is 0.000, subscript is 21
DEBUG6: iOffset is 24, xrate is 0.000, subscript is 22
DEBUG6: iOffset is 30, xrate is 0.000, subscript is 23
DEBUG6: iOffset is 36, xrate is 0.000, subscript is 24
DEBUG6: iOffset is 42, xrate is 0.000, subscript is 25
DEBUG6: iOffset is 48, xrate is 0.000, subscript is 26
DEBUG4: the line of tax rates read in is 0 0 0
DEBUG5: iFields is 27
DEBUG6: iOffset is 0, xrate is 0.000, subscript is 27
DEBUG6: iOffset is 6, xrate is 0.000, subscript is 28
DEBUG6: iOffset is 12, xrate is 0.000, subscript is 29
DEBUG6: iOffset is 18, xrate is 0.000, subscript is 30
DEBUG6: iOffset is 24, xrate is 0.000, subscript is 31
DEBUG6: iOffset is 30, xrate is 0.000, subscript is 32
DEBUG6: iOffset is 36, xrate is 0.000, subscript is 33
DEBUG6: iOffset is 42, xrate is 0.000, subscript is 34
DEBUG6: iOffset is 48, xrate is 0.000, subscript is 35
DEBUG4: the line of tax rates read in is 2.300 2.40 0 00 600 .700 2.800 2.90 0 00 100 0 0
DEBUG5: iFields is 36
DEBUG6: iOffset is 0, xrate is 0.000, subscript is 36
DEBUG6: iOffset is 6, xrate is 0.000, subscript is 37
DEBUG6: iOffset is 12, xrate is 0.000, subscript is 38
DEBUG6: iOffset is 18, xrate is 0.000, subscript is 39
DEBUG6: iOffset is 24, xrate is 0.000, subscript is 40
DEBUG6: iOffset is 30, xrate is 0.000, subscript is 41
DEBUG6: iOffset is 36, xrate is 0.000, subscript is 42
DEBUG6: iOffset is 42, xrate is 0.000, subscript is 43
DEBUG6: iOffset is 48, xrate is 0.000, subscript is 44
DEBUG4: the line of tax rates read in is 0 0 0
From the debug output, the counters I declared( iOffset, iFields, and the loop counters) are producing correct values. It is the fgets and
sscanf that do not seem to be working correctly. They do work correctly in the screen program, and I am not sure what the issue is in the server program. A portion of the data being read fron the file follows:
0.500 0.600 0.700 0.800 0.900 1.000 1.100 1.200 1.300
1.400 1.500 1.600 1.700 1.800 1.900 2.000 2.100 2.200
2.300 2.400 2.500 2.600 2.700 2.800 2.900 3.000 3.100
3.200 3.300 3.400 3.500 3.600 3.700 3.800 3.900 4.000
4.100 4.200 4.300 4.400 4.500 4.600 4.700 4.800 4.900
5.000 5.100 5.200 5.300 5.400 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.600 0.700 0.800 0.900 1.000 1.100 1.200 1.300 1.400
1.500 1.600 1.700 1.800 1.900 2.000 2.100 2.200 2.300
2.400 2.500 2.600 2.700 2.800 2.900 3.000 3.100 3.200
3.300 3.400 3.500 3.600 3.700 3.800 3.900 4.000 4.100
4.200 4.300 4.400 4.500 4.600 4.700 4.800 4.900 5.000
5.100 5.200 5.300 5.400 5.500 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.700 0.800 0.900 1.000 1.100 1.200 1.300 1.400 1.500
1.600 1.700 1.800 1.900 2.000 2.100 2.200 2.300 2.400
2.500 2.600 2.700 2.800 2.900 3.000 3.100 3.200 3.300
3.400 3.500 3.600 3.700 3.800 3.900 4.000 4.100 4.200
4.300 4.400 4.500 4.600 4.700 4.800 4.900 5.000 5.100
5.200 5.300 5.400 5.500 5.600 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.800 0.900 1.000 1.100 1.200 1.300 1.400 1.500 1.600
1.700 1.800 1.900 2.000 2.100 2.200 2.300 2.400 2.500
2.600 2.700 2.800 2.900 3.000 3.100 3.200 3.300 3.400
3.500 3.600 3.700 3.800 3.900 4.000 4.100 4.200 4.300
4.400 4.500 4.600 4.700 4.800 4.900 5.000 5.100 5.200
5.300 5.400 5.500 5.600 5.700 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.900 1.000 1.100 1.200 1.300 1.400 1.500 1.600 1.700
1.800 1.900 2.000 2.100 2.200 2.300 2.400 2.500 2.600
2.700 2.800 2.900 3.000 3.100 3.200 3.300 3.400 3.500
3.600 3.700 3.800 3.900 4.000 4.100 4.200 4.300 4.400
4.500 4.600 4.700 4.800 4.900 5.000 5.100 5.200 5.300
5.400 5.500 5.600 5.700 5.800 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
1.000 1.100 1.200 1.300 1.400 1.500 1.600 1.700 1.800
1.900 2.000 2.100 2.200 2.300 2.400 2.500 2.600 2.700
2.800 2.900 3.000 3.100 3.200 3.300 3.400 3.500 3.600
3.700 3.800 3.900 4.000 4.100 4.200 4.300 4.400 4.500
4.600 4.700 4.800 4.900 5.000 5.100 5.200 5.300 5.400
5.500 5.600 5.700 5.800 5.900 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
This data represents all the tax rates for six tax schedules, there are rates for fifteen tax schedules in all(every tax schedule can have up to
81 rates, most schedules have fewer rates). Any help with this problem is greatly appreciated.