P. 1
Data Structures Using C

Data Structures Using C


|Views: 1,314|Likes:
Published by TB

More info:

Published by: TB on Mar 18, 2009
Copyright:Traditional Copyright: All rights reserved


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less






Now for an example of a program [BIGARRAY.C] with an array of
float type data. This program also has an extra feature to illustrate how
strings can be initialised.

#include "stdio.h"
#include "string.h"
char name1[ ] = "First Program Title";
void main( )
int index;
int stuff[12];

Module 815

Data Structures Using C

Page 813-8

float weird[12];
static char name2[] = "Second Program Title";
for (index = 0; index < 12; index++) {
stuff[index] = index + 10;
weird[index] = 12.0 * (index + 7);

printf("%s\n", name1);
printf("%s\n\n", name2);
for (index = 0; index < 12; index++)
printf("%5d %5d %10.3f\n", index, stuff[index], weird[index]);


The first line of the program illustrates how to initialise 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 including the terminating NULL. Another string is initialised 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. You can think of a staic
declaration as a local constant.

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.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->