B
Blankdraw
....
somewhere, a newbie is dying ...
Is there anybody out there who can help me get the right input
for the following segment? I am trying to read entire records
of 5 (2-digit) integers at a time. It would be best to read the
integers into their own 5 respective variables.
I thought I had it. I've redone my program so many different ways
I am coming to the same conclusion I did when I tried to do it
several years ago: that it cannot reasonably be coded in any popular
language. I just now gave up on reading each individual integer
because I was getting output that looked like my
fscanf(fileptr, "%i", &n); statement was reading entire records instead.
My first record is: 17 40 41 42 46
The following code seems to go only once thru the first 2 FOR loops
(on step-through) and bombs about 46 times thru on the 3rd FOR loop,
with a:
"unhandled exception -- access violation" error.
Using MVC/C++ 4.2 -- is this too "old."
Please HELP (WTH IS GOING ON???)
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <math.h>
int main()
{ /* 52 rows x 120 active columns */
int current[53][122] = {0}; /* include extra R & C for testing */
int n1, n2, n3, n4, n5;
int row=0, col=1, cycle=0;
FILE *fileptr;
if ((fileptr = fopen("test_data.txt", "r")) == NULL )
....error checking ...
for (cycle = 0; cycle < 120; cycle++) /* 5 entries x 120 data recs */
{ /* was 1 to 601 cycles */
fscanf(fileptr, "%i", "%i", "%i", "%i", "%i", &n1, &n2, &n3, &n4, &n5);
printf("%i", "%i", "%i", "%i", "%i", n1, n2, n3, n4, n5);
for (row = 0; row < (n1 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n1 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n1 +1); row < (n2 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n2 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n2 + 1); row < (n3 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n3 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n3 + 1); row < (n4 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n4 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n4 + 1); row < 52; row++)
{
current[row][col] = current[row][col - 1];
if (n5 == row) {
current[row][col] = current[row][col] + 1;
}
}
col++;
}
somewhere, a newbie is dying ...
Is there anybody out there who can help me get the right input
for the following segment? I am trying to read entire records
of 5 (2-digit) integers at a time. It would be best to read the
integers into their own 5 respective variables.
I thought I had it. I've redone my program so many different ways
I am coming to the same conclusion I did when I tried to do it
several years ago: that it cannot reasonably be coded in any popular
language. I just now gave up on reading each individual integer
because I was getting output that looked like my
fscanf(fileptr, "%i", &n); statement was reading entire records instead.
My first record is: 17 40 41 42 46
The following code seems to go only once thru the first 2 FOR loops
(on step-through) and bombs about 46 times thru on the 3rd FOR loop,
with a:
"unhandled exception -- access violation" error.
Using MVC/C++ 4.2 -- is this too "old."
Please HELP (WTH IS GOING ON???)
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <math.h>
int main()
{ /* 52 rows x 120 active columns */
int current[53][122] = {0}; /* include extra R & C for testing */
int n1, n2, n3, n4, n5;
int row=0, col=1, cycle=0;
FILE *fileptr;
if ((fileptr = fopen("test_data.txt", "r")) == NULL )
....error checking ...
for (cycle = 0; cycle < 120; cycle++) /* 5 entries x 120 data recs */
{ /* was 1 to 601 cycles */
fscanf(fileptr, "%i", "%i", "%i", "%i", "%i", &n1, &n2, &n3, &n4, &n5);
printf("%i", "%i", "%i", "%i", "%i", n1, n2, n3, n4, n5);
for (row = 0; row < (n1 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n1 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n1 +1); row < (n2 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n2 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n2 + 1); row < (n3 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n3 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n3 + 1); row < (n4 + 1); row++)
{
current[row][col] = current[row][col - 1];
if (n4 == row) {
current[row][col] = current[row][col] + 1;
}
}
for (row = (n4 + 1); row < 52; row++)
{
current[row][col] = current[row][col - 1];
if (n5 == row) {
current[row][col] = current[row][col] + 1;
}
}
col++;
}