TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Mark Trickett
from: George White
date: 1998-08-06 10:04:00
subject: Array problems

Hi Mark,

You asked:

MT>Hello All, I have a somewhat less than pristine conversion chart for
MT>converting between millimeters and inches. Rather than making a
MT>grotty photocopy, I thought to write a program to create the
MT>tabulated data and place it in a text file that can be printed.

MT>I settled down and put together the following code using the Borland
MT>TC3 for DOS IDE. When I tell it to "Build All", I get four linker
MT>errors;

MT>Compiling table1.c
MT>Linking ..\..\out\mm2in.exe
MT>Linker Error: Undefined Symbol FIWRQQ in module table1.c
MT>Linker Error: Undefined Symbol FIDRQQ in module table1.c
MT>Linker Error: Undefined Symbol FJSRQQ in module table1.c
MT>Linker Error: Undefined Symbol FISRQQ in module table1.c

MT>I am attempting to do this as a project, and I have found that the
MT>critical material is the references to "inches[j,i]" within the
MT>loops. If I comment such references out, the linker errors go away,
MT>but so does the functionality.

They occur because floating point isn't enabled. This is under
Options->Compiler->Advanced Code Generation.

 code (for now).

MT>There is probably something glaringly obvious to the more
MT>experienced programmers in the echo, but it has me stuffed!!

There is an error in the fprintf() and a number of other bits of poor
codeing practise. I'll explain:-

/*  **************************************************  */
/*                                                      */
/*  tabulated data program to produce a millimeter      */
/*  to inch conversion table                            */
/*  Mark Trickett                                       */
/*  started 2nd of August 1998                          */
/*                                                      */
/*  **************************************************  */

#include 
#include 
#include 

extern void _floatconvert();
#pragma extref _floatconvert

/* Unless absolutely necessary, all declarations shuld be within main() */
/* so we move the "FILE *cvrt_file;" */

int main(int argc, char *argv[])
{
FILE *cvrt_file;

/*    char *table_file, nl[]="\n"; */
/* variables not needed (see later) */

    int i, j;

/* Apologies for the use of C++ comments below, but it gets round the */
/* problem of nested C comments */

/* You've used a BASIC style array declaration, not a C one :-( */
//    float inches[100,10]/*, mm2inch=25.4 */;
/* it should be :- */
//    float inches[100][10]/*, mm2inch=25.4 */;
/* but the inch[][] array is only used during calculation, and isn't */
/* really needed (see later) */

    if (argc != 2 )
        {
        printf("\nUseage: require an output file name");
        printf("\nand nothing else");
        return (1);
        }

/*    table_file = argv[1];*/  /* Not needed, you can use argv[1] directly */

/* so change */
/*    if((cvrt_file=fopen(table_file,"rb"))!= NULL) */
/* to */
    if((cvrt_file=fopen(argv[1],"wb"))!= NULL)
        {
/* The loop is much more efficeint if we provide the base value for */
/* each line rather than doing a multiply by 10 in each calculation */
/*      for (j=0; j<100; j++) */
        for (j=0; j<1000; j+=10)
            {
/*          fprintf(cvrt_file,"%s",*nl); */
/* Printing a newline that way is inefficient, better is to use the */
/* '\n' provided by the language */
            fprintf(cvrt_file,"\n");
            for (i=0; i<10; i++)
                {
                /* this is the business part, and the
                   source of the linker errors */
/*                inches[j,i]=((i + (10 * j)) / 25.4 ); */
/* The BASIC style array should be changed to: */
/*              inches[j][i]=((i + (10 * j)) / 25.4 ); */
/*              fprintf(cvrt_file,"%f9.4",inches[j][i]); */
/* You've got the format string wrong, the 'f' is the last element after the */
/* prescision specifiers, not the first */
/* But the use of inches[][] is redundant, and you can do */
                fprintf(cvrt_file,"%9.4f",(i + j) / 25.4);
                }
            }
/* You should really close the file here */
    fclose (cvrt_file);
        }
        return (0);
}

If you extract the code to here it should compile correctly for you after
you've set the floating point option.
I hope you don't take the comments the wrong way, they are intended to
make you think about how you are doing things, not to put you down.

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)
SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728 810
SEEN-BY: 639/252 670/213 218
@PATH: 440/4 255/1 440/1 80 252/356 140/1 270/101 396/1 633/260 635/506 728
@PATH: 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.