twitter
    Find out what I'm doing, Follow Me :)

An Array Of Floating Point Data

Load and display the program named bigarray.c for an example of a program with an array of "float" type data.

/* NOTE
This example has been modified to use another integer type variable
instead
of a float type variable due to the problems in the float library with the
HI-TECH C Compiler. The compiler returns no fatal errors when the type
float
variable is used and the float library included at link time but the Xrel
file
produces a address error. The original code is commented out so that you
can
still see that was intended in the tutorial.

*/
char name1[ ] = "First Program Title";


main()
{
int index;
int stuff[12];
/* float weird[12]; */
int weird[12];
static char name2[ ] = "Second Program Title";
for (index = 0;index < 12;index++) {
stuff[index] = index + 10;
/* weird[index] = 12.0 * (index + 7); */
weird[index] = 12 * (index + 7);
}
printf("%s\n",name1);
printf("%s\n\n",name2);
for (index = 0;index< 12;index++) {
printf("%5d %5d %5d\n",index,stuff[index],weird[index]);
/* printf("%5d %5d %10.3f\n",index,stuff[index],weird[index]); */
}
}



This program has an extra feature to illustrate how strings can be initialized. The first line of the program illustrates to you how to initialize a string of characters. Notice that the square brackets are empty leaving it up to the compiler to count the characters and allocate enough space for our string. Another string is initialized in the body of the program but it must be declared "static" here. This prevents it from being allocated as an "automatic" variable and allows it to retain the string once the program is started. There is nothing else new here, the variables are assigned nonsense data and the results of all the nonsense are printed out along with a header. This program should also be easy for you to follow, so study it until you are sure of what it is doing before going on to the next topic.