Blankdraw wrote:
CBFalconer <cb********@yahoo.com> wrote in message
Besides the other comments, you still haven't posted a complete,
compilable source exhibiting your problem.
I assume this means someone thinks having the full code listing will
be of benefit in resolving the output-column increment problem....so:
I am going to regret this, but the first thing I did was reformat
your source into something with consistent indentation and
eliminate the double spacing of each line, which is pure
foolishness.
The result does indeed compile, with the following warnings:
[1] c:\c\junk>gcc junk.c
junk.c: In function `main':
junk.c:8: warning: missing braces around initializer
junk.c:8: warning: (near initialization for `current[0]')
junk.c:19:46: warning: "/*" within comment
junk.c:10: warning: unused variable `next'
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
There is no such include file in standard C. There appears to be
a flaw in gcc 3.2.1 for DJGPP which allows this to go
unchallenged.
#include <math.h>
What do you want this for?
int main()
Use "int main(void)" or "int main(int argc, char **argv)". You
didn't omit the int return type for main, which is good.
{
int current[52][121] = {0}; /* 52 rows x 120 active columns */
int n, temp;
int next=1, row=0, col=1, cycle=0;
double EOL; /* End-Of-Line */
What in heavens name is this for?
FILE *fileptr;
/* point to a data value */
if ((fileptr = fopen("test_data.txt", "r")) == NULL ) {
printf("Error: Cannot open input file\n");
exit(0);
It might be better to signal an error with "exit(EXIT_FAILURE)",
or "return(EXIT_FAILURE)", which you can do since you included
stdlib.h.
}
/* while (!feof(fileptr)) /* compare data from fscanf - below */
for (cycle = 1; cycle < 7; cycle++) /* 5 entries x 120 data recs */
This will use cycle values of 1 through 6, for 6 entries. I see
no relationship to the comments.
{ /* use 7 test values */
fscanf(fileptr, "%i", &n); /* <---get next data value */
I doubt you really want fscanf here. You omitted to include the
content of test_data.txt, so we have no idea what you are trying
to input.
Things now degenerate into total confusion. You need to break
your code up into better modules. See end.
for (row = 0; row < 51; row++) /* 52 rows = 52 possibilities */
{
current[row][col] = current[row][col - 1];
if (n == row)
{
temp = current[row][col] + 1;
current[row][col] = temp; /* current[r][c]++ ??? */
}
}
EOL = floor(cycle / 5);
if ( EOL == (cycle / 5 ) ) { /* cycles 0 to 4 goto col 1 */
col++; /* note: cycle #0 / 5 -> NoGo */
/* next 5 (#6 - #10) goto col 2 */
}
}
for (row = 0; row < 52; row++) {
printf("\n");
for (col = 1; col < 121; col++) {
printf ("%i ", current[row][col]);
}
}
/* for (row = 0; row < 52; row++) */
/* { */
/* printf("\n"); */
/* for (col = 0; col < 120; col++) { */
/* printf ("%i ", current[row][col]); */
/* } */
/* } */
fclose(fileptr);
if ((fileptr = fopen("pb.txt", "w")) == NULL ) /* pb.txt is pb.out */
{
printf("Error: Cannot open input file\n");
exit(0);
}
/* while (!feof(fileptr)) */
for (row = 0; row < 52; row++) { /* dump array into text file */
fprintf (fileptr, "\n");
for (col = 1; col < 121; col++) {
fprintf (fileptr, "%2d ", current[row][col]);
}
}
fclose(fileptr);
return 0;
}
Strip out code that has been commented out. It does nothing but
add confusion.
I suggest you start over with a better organization:
/* the necessary includes */
/* Some #defines for any numbers you use other than 1 */
int fillcurrent(int *current, FILE *fp)
{
/* code this, return 0 for failure */
}
int dumpcurrent(int *current, FILE *fp)
{
/* code this, return 0 for failure */
}
int main(int argc, char **argv)
{
/* some variables, including current and filepointers */
/* code to open input and output files
using the command line args to supply names */
/* a call to a function to fill the 'current' array */
if (fillcurrent(current, fpin) {
/* a call to a function to dump the 'current' array */
if (dumpcurrent(current, fpout) {
return 0; /* success */
}
}
return EXIT_FAILURE;
}
and read the C faq, especially about multi dimensional array and
how to pass and manipulate them. If you don't like my suggestions
for error returns, change them.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!