B
Blankdraw
I thought I cut out for myself a "simple" 1-module ANSI C programming
task.
I will in fact require extensive use of step-thru debugging.
My old MS Visual C Developer Studio 4.2 should do this, but the
step-through debugger wants me to locate several files which look like
system files. I don't know what its problem is. The files are:
CHKSTK.ASM, CRT0.C, READ.C
Is there someone here familiar with MVC DS 4.2 that can explain how to
use the stepper? I have a slew of questions that will overload this
forum if I were to keep posting them.
It doesn't seem like the problem should be so hairy (2 program
approaches follow, no warnings or errors, w/o using stepper):
APPROACH # 1 ***********************************************************
My program takes a text file of 5 integers per line, 140-odd lines of
this, and basically puts it into an array. The lines are separated
by LF-CR, of course.
The integers have to be matched in value with the rows in the array,
and my formatted printout will show 52 rows of integers. The
integers will be exactly as numerous as the rows in the text file are,
so it will show 52 rows by about 140 columns.
The array rows will be made of integers only increasing in value,
because each of the 5 integers-per-line in the text will be matched
with a given array row according to the integer's actual value, and
these integers repeatedly match and increment the row values as the
rows progress from left-to-right (as read). Many previous array
values repeat because there is not often a match with the text data.
INPUT n1 n2 n3 n4 n5 LFCR
n6 n7 n8 n9 n10 ....
OUTPUT
0 0 0 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 (... 140 columns of this )
....5 5 5 5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 3 3 3 3 3 3 3 3 3 3 ... 3 3 3
3 4 4 4
(52 rows of this)
#include <stdio.h>
#include <fcntl.h> /* used by open() */
#define SIZE 1024 /* 140 x 7bytes, incl 1LF */
#define CTRL_Z '\032' /* text-mode EOF */
main(argc,argv)
int *argv[];
{
char buffer[SIZE]; /* hafta make do w/o int decl */
int fd;
long int n=1;
long count = 0;
int current[52][141]; /* r52c141 array, built-up */
int row; /* from repeat passes of a */
int col; /* current element index */
/* 52r140c printout omits init col - used for its 0's */
for (row = 0; row < 52; row++) /* initialize output array */
{
for(col = 0; col < 141; col++)
current[row][col] = 0;
}
row = 0;
col = 1;
fd = open(argv[1], O_RDONLY | O_TEXT);
/* while (n != CTRL_Z ) /* big loop - begin new records to EOF */
while (n > 0 ) /* big loop - begin new dwg date to EOF
*/
{ col++; /* only cols need init 0-buffer: (r[1]c[2] */
while ( (n = read(fd,buffer,SIZE)) != '\n' ) /* skip CR-LF */
{
for ( row = 0; row = 52; row++ )
{
current[row][col] = current[row][col-1]; /* copy prv */
if ( n == row )
{
current[row][col] = current[row][col-1] + 1;
} /* this IS now a match, so increment the copy */
}
}
/* hey - break-out read file into buffer, access data 1, access buffer
many */
}
for(row = 0; row < 52; row++)
{
printf("\n");
for (col = 0; col < 140; col++)
printf ("%d ", current[row][col]);
}
/* for(row = 1; row = 52; row++) */
/* { */
/* printf ("\n"); */
/* for (col = 1; col = 140; col++) */
/* printf ("%i ", current[row][col]); */
/* } */
return(0);
}
APPROACH # 2 *****************************************************
#include <stdio.h>
#include <fcntl.h> /* used by open() */
#define SIZE 5 /* best = ALL file.txt = 140 x 7bytes,
incl 1LF */
#define CTRL_Z '\032' /* text-mode EOF */
main(argc,argv)
int *argv[];
{
char buffer[SIZE]; /* hafta make do w/o int decl */
int fd;
int n = 1;
int count = 0;
int current[52][141]; /* r52c141 array, built-up */
int row; /* from repeat passes of a */
int col; /* current element index */
/* 52r140c printout omits init col - used for its 0's */
for (row = 0; row < 52; row++) /* initialize output array */
{
for(col = 0; col < 141; col++)
current[row][col] = 0;
}
row = 0;
col = 1;
fd = open(argv[1], O_RDONLY | O_TEXT);
for (count = 0; count < 140; count++) /* big loop - begin records, to
EOF */
{ /* use ONLY det. loops for try-out
coding */
/* fgets(buffer, sizeof buffer, fd); /* read 1 record into
5-byte 'buffer' */
sscanf(fd, "%2i%2i%2i%2i%2i", &buffer[0], &buffer[1], &buffer[2],
&buffer[3], &buffer[4]);
col++; /* only cols need init
0-buffer (r[1]c[2] */
for (n=0; n<5; n++)
{
for (row = 0; row < 52; row++)
{
current[row][col] = current[row][col-1]; /* copy prv */
if ( buffer[n] == row ) {
current[row][col] = current[row][col-1] + 1;
} /* this IS now a match, so increment the copy */
}
}
}
/* for(row = 0; row < 52; row++) */
/* { */
/* printf("\n"); */
/* for (col = 0; col < 140; col++) */
/* printf ("%d ", current[row][col]); */
/* } */
return(0);
}
task.
I will in fact require extensive use of step-thru debugging.
My old MS Visual C Developer Studio 4.2 should do this, but the
step-through debugger wants me to locate several files which look like
system files. I don't know what its problem is. The files are:
CHKSTK.ASM, CRT0.C, READ.C
Is there someone here familiar with MVC DS 4.2 that can explain how to
use the stepper? I have a slew of questions that will overload this
forum if I were to keep posting them.
It doesn't seem like the problem should be so hairy (2 program
approaches follow, no warnings or errors, w/o using stepper):
APPROACH # 1 ***********************************************************
My program takes a text file of 5 integers per line, 140-odd lines of
this, and basically puts it into an array. The lines are separated
by LF-CR, of course.
The integers have to be matched in value with the rows in the array,
and my formatted printout will show 52 rows of integers. The
integers will be exactly as numerous as the rows in the text file are,
so it will show 52 rows by about 140 columns.
The array rows will be made of integers only increasing in value,
because each of the 5 integers-per-line in the text will be matched
with a given array row according to the integer's actual value, and
these integers repeatedly match and increment the row values as the
rows progress from left-to-right (as read). Many previous array
values repeat because there is not often a match with the text data.
INPUT n1 n2 n3 n4 n5 LFCR
n6 n7 n8 n9 n10 ....
OUTPUT
0 0 0 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 (... 140 columns of this )
....5 5 5 5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 3 3 3 3 3 3 3 3 3 3 ... 3 3 3
3 4 4 4
(52 rows of this)
#include <stdio.h>
#include <fcntl.h> /* used by open() */
#define SIZE 1024 /* 140 x 7bytes, incl 1LF */
#define CTRL_Z '\032' /* text-mode EOF */
main(argc,argv)
int *argv[];
{
char buffer[SIZE]; /* hafta make do w/o int decl */
int fd;
long int n=1;
long count = 0;
int current[52][141]; /* r52c141 array, built-up */
int row; /* from repeat passes of a */
int col; /* current element index */
/* 52r140c printout omits init col - used for its 0's */
for (row = 0; row < 52; row++) /* initialize output array */
{
for(col = 0; col < 141; col++)
current[row][col] = 0;
}
row = 0;
col = 1;
fd = open(argv[1], O_RDONLY | O_TEXT);
/* while (n != CTRL_Z ) /* big loop - begin new records to EOF */
while (n > 0 ) /* big loop - begin new dwg date to EOF
*/
{ col++; /* only cols need init 0-buffer: (r[1]c[2] */
while ( (n = read(fd,buffer,SIZE)) != '\n' ) /* skip CR-LF */
{
for ( row = 0; row = 52; row++ )
{
current[row][col] = current[row][col-1]; /* copy prv */
if ( n == row )
{
current[row][col] = current[row][col-1] + 1;
} /* this IS now a match, so increment the copy */
}
}
/* hey - break-out read file into buffer, access data 1, access buffer
many */
}
for(row = 0; row < 52; row++)
{
printf("\n");
for (col = 0; col < 140; col++)
printf ("%d ", current[row][col]);
}
/* for(row = 1; row = 52; row++) */
/* { */
/* printf ("\n"); */
/* for (col = 1; col = 140; col++) */
/* printf ("%i ", current[row][col]); */
/* } */
return(0);
}
APPROACH # 2 *****************************************************
#include <stdio.h>
#include <fcntl.h> /* used by open() */
#define SIZE 5 /* best = ALL file.txt = 140 x 7bytes,
incl 1LF */
#define CTRL_Z '\032' /* text-mode EOF */
main(argc,argv)
int *argv[];
{
char buffer[SIZE]; /* hafta make do w/o int decl */
int fd;
int n = 1;
int count = 0;
int current[52][141]; /* r52c141 array, built-up */
int row; /* from repeat passes of a */
int col; /* current element index */
/* 52r140c printout omits init col - used for its 0's */
for (row = 0; row < 52; row++) /* initialize output array */
{
for(col = 0; col < 141; col++)
current[row][col] = 0;
}
row = 0;
col = 1;
fd = open(argv[1], O_RDONLY | O_TEXT);
for (count = 0; count < 140; count++) /* big loop - begin records, to
EOF */
{ /* use ONLY det. loops for try-out
coding */
/* fgets(buffer, sizeof buffer, fd); /* read 1 record into
5-byte 'buffer' */
sscanf(fd, "%2i%2i%2i%2i%2i", &buffer[0], &buffer[1], &buffer[2],
&buffer[3], &buffer[4]);
col++; /* only cols need init
0-buffer (r[1]c[2] */
for (n=0; n<5; n++)
{
for (row = 0; row < 52; row++)
{
current[row][col] = current[row][col-1]; /* copy prv */
if ( buffer[n] == row ) {
current[row][col] = current[row][col-1] + 1;
} /* this IS now a match, so increment the copy */
}
}
}
/* for(row = 0; row < 52; row++) */
/* { */
/* printf("\n"); */
/* for (col = 0; col < 140; col++) */
/* printf ("%d ", current[row][col]); */
/* } */
return(0);
}