473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Wrong abt semi-finished program - why no output?

I'm getting NO errors and 2 warnings with this code. I thought I was
ready to write the output-formatting segment, but may be way off the
mark now. The warnings say that "OPEN() and READ() are undeclared -
assuming an external is returning integer values." This is not the
source of the problem.
Step-Thru causes the system to demand the location of system-sounding
files like: CHKSTK.ASM, CRT0.C, READ.C. With no real debugger
feedback, I can't do nuthin. Step-Thru seems to get caught in an
infinite loop, but I can't figger what its doing.
Can someone here tell me why my console is idle but for the blinking
cursor? I've come a long way to give up now.

My program takes a text file of 5 integers per line, 140-odd lines of
this, and basically transforms it into a 2D 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 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;
/* problem has to be between here and the output loops */

fd = open(argv[1], O_RDONLY | O_TEXT);
/* while (n != CTRL_Z ) /* big loop - begin new dwg date 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 */
}
}
/* shld break-out read file into buffer, access data 1, access buffer
many */
}

for(row = 0; row < 52; row++) /* output loops */
{
printf("\n");
for (col = 0; col < 140; col++)
printf ("%d ", current[row][col]);
}
return(0);
}
Nov 13 '05 #1
3 2023

"Blankdraw" <sp********@aol.com> wrote in message news:9f**************************@posting.google.c om...
/* while (n != CTRL_Z ) /* big loop - begin new dwg date 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 */
{

n is a character count, not something you can sensibly test against '\n'
or ^Z (and in any case, you'd do better using stdio functions).

John.
Nov 13 '05 #2
Blankdraw wrote:
I'm getting NO errors and 2 warnings with this code. I thought I was
ready to write the output-formatting segment, but may be way off the
mark now. The warnings say that "OPEN() and READ() are undeclared -
assuming an external is returning integer values." This is not the
source of the problem.
Step-Thru causes the system to demand the location of system-sounding
files like: CHKSTK.ASM, CRT0.C, READ.C. With no real debugger
feedback, I can't do nuthin. Step-Thru seems to get caught in an
infinite loop, but I can't figger what its doing.
Can someone here tell me why my console is idle but for the blinking
cursor? I've come a long way to give up now.

My program takes a text file of 5 integers per line, 140-odd lines of
this, and basically transforms it into a 2D 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 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)
The above specification makes *no* sense. Please try writing it in
English. Your code, retained at the EOM, is not written in standard C. In
fact, it is written in K&R C using non-standard functionality.

Here is a start for what it *appears* you are trying to do:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 1024

int main(int argc, char *argv[])
{
char buffer[SIZE];
FILE *fd;
int current[52][141] = { {0} };
int row;
int col;

if (argc != 2) { /* process error here */
exit(EXIT_FAILURE);
}
if (!(fd = fopen(argv[1], "r"))) { /* process error here */
exit(EXIT_FAILURE);
}

for (col = 1; fgets(buffer, sizeof buffer, fd); col++) {
char *token;
int n;
for (token = strtok(buffer, " "); token; token = strtok(0, " ")) {
if (!sscanf(token, "n%d", &n)) /* process error */
;
/* use this read integer 'n' however it is that you do so */
}
}

return 0;
}
[EOM: original code]
#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;
/* problem has to be between here and the output loops */

fd = open(argv[1], O_RDONLY | O_TEXT);
/* while (n != CTRL_Z ) /* big loop - begin new dwg date 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 */
}
}
/* shld break-out read file into buffer, access data 1, access buffer
many */
}

for(row = 0; row < 52; row++) /* output loops */
{
printf("\n");
for (col = 0; col < 140; col++)
printf ("%d ", current[row][col]);
}
return(0);
}

--
Martin Ambuhl

Nov 13 '05 #3
On 10 Aug 2003 13:17:36 -0700
sp********@aol.com (Blankdraw) wrote:

<snip useless explanation of what it should be doing which I won't bother to
read because it's too long and complicated, since the author didn't take the
time to summarize it in a few lines>

#include <stdio.h>
#include <fcntl.h> /* used by open() */
#define SIZE 1024 /* 140 x 7bytes, incl 1LF */
#define CTRL_Z '\032' /* text-mode EOF */
platform specific
main(argc,argv)
int *argv[];
K&R style function definition. Implicit int. the above line is pointless if you
really want what you did here, but I doubt it. It was char *argv[], last time I
checked. Do they do things this way where you're from?
{
char buffer[SIZE]; /* hafta make do w/o int decl */
hafta? w/o? nice english in the comment, pal.
int fd;
long int n=1;
long count = 0;
int current[52][141]; /* r52c141 array, built-up */
magic numbers!
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;
/* problem has to be between here and the output loops */

fd = open(argv[1], O_RDONLY | O_TEXT);
open() takes a pointer to a character. argv[1] is a pointer to an integer in
this code. And you never checked if argv[1] was even given. Try using argc for
that.
/* while (n != CTRL_Z ) /* big loop - begin new dwg date to EOF
*/
your compiler must've warned you about this one.
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 */


read() returns the number of bytes read. So it's pointless to check it against
'\n' (and for the record, a CRLF is "\r\n"), or to check n to CTRL_Z in the
outer loop(which I think you commented out). Although it's hard to see what the
outer loop IS, or what you commented out or not. I'm not reading any more of
this, go fix your code. The way I see it if this does what you want it to you're
lucky, because it's undefined and obfuscated.

And make it readable next time? The indentation sucks badly. Spaces here, tabs
there... When posting code to a newsgroup, try indenting with spaces(4 of them).
No tabs. Get rid of all code commented out unless it makes the code more
understandable.
Also, don't let lines be longer than 75-80 characters.

--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k):(x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh$%c","-34*1'.+(,03#;+,)/'///*");}
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jhomp ssens | last post by:
I would like to create a pulldown menu which is semi-transparent....that is, you can see the text and graphics behind it when it is pulled down. The effect I'm looking for can be seen at...
3
by: John Black | last post by:
I have the following code trying to use bind1st, class C1{ ... }; class C2{ ... };
16
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more...
5
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
After seeing the following documentation: http://www.croczilla.com/~alex/reference/javascript_ref/stmt.html#1051663 I decided to try using a try/catch block in my own JavaScript test file. But it...
2
by: David Scemama | last post by:
Hi, I'm looking for a way to display semi graphic characters in a multi line text control or in a rich text control. I've tried with all the characters of the extended ASCII table (code page...
27
by: StevePBurgess | last post by:
With a string of authors such as: Carson, David, Milne, Rebecca, Pakes, Francis J., Shalev, Karen, Shawyer, Andrea I would like to write a function to change every other comma into a semi...
2
by: Trond Michelsen | last post by:
Hi. I have a transparent PNG-image that I would like to display on top of the rest of the web page. I've already got this part working. But, I'd like the background (as in "the part of the image...
0
by: James Arnold | last post by:
I am trying to use a semi transparent PNG as the form background, allowing you to see through certain parts. The intention is similar to a skinnable form like launchy, with semi-transparent pixels...
9
by: JamesF1982 | last post by:
Hey everyone, My question is related to HTML, Javascript, CSS and ASP.NET but i think it belongs here! Upon an event i am trying to add a semi-transparent colour across the page so the...
26
by: machineghost | last post by:
First off, let me just say that as someone with no DBA training whatsoever, any help I can get with this issue will be very, very much appreciated. My company recently migrated our database from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.