Monash University > CSSE > CSE1303 > Part A > Tutorials > Tutorial A3
This tute covers material from lectures A05 to A06.
There may not be time in the tutorial to cover all of these questions. Attempt at least the ones marked with an asterisk before the tutorial; these are the ones that will be focussed on during the class. If you have specific questions about unmarked questions, you can ask the tutor about them during the tutorial. If you want further revision questions, suggestions of questions from the textbooks are provided at the end of the tutorial sheet.
Note: The purpose of tutorials is not simply to give you the answers to these questions! (Solutions will be released in about a week online, so if all you want is the answers, there are easier ways.)
struct ItemRec
{
int number;
char name[80];
};
typedef struct ItemRec Item;
Item* myItems;
Write a C statement so that myItems points to a dynamically created array of 10 structures of type Item.
/* This program is based on a program in
* "The C Programming Language",
* by Brian W. Kerninghann and Dennis M. Richie.
*/
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* Count lines, words, and characters in the input */
void main()
{
int c;
int state;
long nl;
long nw;
long nc;
state = OUT;
nl = nw = nc = 0;
c = getchar();
while (c != EOF)
{
nc++;
if (c == '\n')
{
nl++;
}
if (c == ' ' || c == '\n' || c == '\t')
{
state = OUT;
}
else if (state == OUT)
{
state = IN;
nw++;
}
c = getchar();
}
printf("%ld %ld %ld\n", nl, nw, nc);
}
Deitel & Deitel (2e)
Self Review Exercises: 12.1 a, b, g
Last modified: Tuesday 02 December 2003 22:29:33