... Massachusetts Institute of Technology
Department of Electrical Engineering and Computer Science
6.087: Practical Programming inC
IAP 2010
Problem Set 4
Pointers. Arrays. Strings. Searchingand ... string tokenizer, the function strspn() computes the index of the
first non-delimiter character in our string. Using pointers or array indexing (your choice),
implement the strspn() function. In ... to locate a character in another string, you may
use the function strpos(), which is declared below:
int s t r p o s ( const char s t r , const char ch ) ; ∗
This function returns the index...
... function. In order to locate a character in another string, you may
use the function strpos(), which is declared below:
int s t r p o s ( const char s t r , const char ch ) ; ∗
This function ...
2
(a) In the context of our string tokenizer, the function strspn() computes the index of the
first non-delimiter character in our string. Using pointers or array indexing (your choice),
implement ... The function strcspn() computes the index of the first delimiter character in our string.
Here’s the declaration of strcspn():
unsigned int s t r c s p n ( const char ∗ s t r , const char ∗...
...
Massachusetts Institute of Technology
Department of Electrical Engineering and Computer Science
6.087: Practical Programming inC
IAP 2010
Problem Set 5 – Solutions
Pointers. Arrays. Strings. Searching ... test code to illustrate the working of each of the above functions.
All the code and sample outputs should be submitted.
1
MIT OpenCourseWare
http://ocw.mit.edu
6.087 Practical Programming in ...
return ++count ;
}
/∗
@funct i o n main
@desc t e s t s b in ar y t r e e f u n c t i o n s
∗/
int main ( )
{
st ruc t tnode ∗ ro o t=NULL;
int count =0;
/∗ adding e le m e n ts ∗/
r o...
... int N);
int compare(int *m, int *n);
int main(void)
{
42
CHAPTER 10: Pointers to Functions
Up to this point we have been discussing pointers to data objects. C also permits the
declaration ... *p, int width, int N,
int(*fptr)(const void *, const void *));
int compare_string(const void *m, const void *n);
int compare_long(const void *m, const void *n);
int main(void)
{
int ... object pointed to. (i.e. 2 for an integer, 4 for a
long, etc.).
Since a block of 10 integers located contiguously in memory is, by definition, an array of
integers, this brings up an interesting...
... types of custom
controls you can create and see how to set up a custom control project. You’ll then continue to
create user controls, which combine other controls into reusable groups (Chapter ... this type of scattered user interface
coding to a more elegant approach, you need to stop thinking in terms of windows and controls
and start looking at a user interface as an entire interrelated ... can be a static method or an instance method. You can then invoke it later.
// Here we assume that the code contains a function named CapitalizeString.
stringProcessor = new StringProcessFunction(CapitalizeString);
//...
... style, andin so doing, it also discusses the architecture frame-
work, target architecture, architecture roadmap, and many of the architectures that are in
common use, including enterprise, application, ... penName
49W WINDOWS PeformanceCounter pfmc pfmcName
50W WINDOWS PictureBox picb picbName
51W WINDOWS Point pnt pntName
52W WINDOWS PrintController prtc prtcName
53W WINDOWS PrintDocument prtd ... Insert spaces
• Keep tabs
Indentation
• Indent block contents
• Indent open and close braces
• Indent case contents
• Indent case labels
• Label indentation
• Place goto labels in leftmost column
•...
... WINDOWS Color clr clrName
8W WINDOWS ColorPalette clrp clrpName
9W WINDOWS ComboBox cb cbName
10W WINDOWS ContextMenu ctm ctmName
11W WINDOWS CrystalReportViewer crv crvName
12W WINDOWS Cursor csr csrName
13W ... penName
49W WINDOWS PeformanceCounter pfmc pfmcName
50W WINDOWS PictureBox picb picbName
51W WINDOWS Point pnt pntName
52W WINDOWS PrintController prtc prtcName
53W WINDOWS PrintDocument prtd ... expressions
• Insert space within parentheses of type casts
• Insert space within flow control construct parentheses
• Insert space after cast
• Spacing for brackets
• Insert space before open square bracket
•...
... communications, and the interaction among them, and is a customized blend
of an Electrical Engineering degree with a Computer Science degree.
The computer engineering curriculum includes courses ... Association for Computing Machinery (ACM), the Association
for Information Systems (AIS), and the Institute of Electrical and Electronics
Engineers Computer Society (IEEE-CS)—produced a cooperative ... sequence includes calculus I
and II (and in many cases, calculus III) as well as discrete mathematics. Some students
also study linear algebra and probability and statistics. A computer science...
... such as .C, .cpp, .cxx,
or
.cc.
NAVIGATING THE DISK
ForinformationonusingtheAcrobattoolbarandotherAcrobatcommands,consult
the Help document within Acrobat. See especially the section “Navigating ... program listings and compiled program code. In this way, the reader gains
increased confidence in the accuracy of the computer program listings appearing
in the text. In fact, with just two exceptions, ... It takesplaceonanunbounded
rectangular grid in which each cell can either be occupied by an organism or not.
Occupied cells are called
alive; unoccupied cells are called dead. Which cells are
definitions
alive...
... having included more comments!
White space White space includes blank characters (spaces), tabs,
and blank lines - all the empty space ignored by the compiler (excluding the
necessary space between ... consequences of stochasticity can be
examined and an understanding of the effects of various assumptions can
be gained using these rather biologically unrealistic processes. In addition
to stochastic ... requiring much time, patience, and money. Things
change in Unix (and C) , too, but backward compatibility is much less of a problem.
xiv Preface
20%
is spent discussing ecological problems and...
... speci c to that instance. For example, each
instance for C will contain a reference to the shared information about strokes
and shapes, and it might also contain the exact location for that instance ... the collection
of objects, visiting each object in turn. Each action method contains something
like a switch statement that defines the details of the action for each subclass in the
collection ... Reading 223
6.7 Exercises 223
6.8 Projects 226
III SortingandSearching 229
7 Internal Sorting 231
7.1 Sorting Terminology and Notation 232
7.2 Three Θ(n
2
) Sorting Algorithms 233
7.2.1 Insertion...
... instance, the code examples provide less parameter checking than is sound
programming practice, since including such checking would obscure rather than il-
luminate the text. Some parameter checking ... number of practical issues related to
programming, including good coding and documentation style. For an excellent
(and entertaining!) introduction to the difficulties involved with writing large ... speci c to that instance. For example, each
instance for C will contain a reference to the shared information about strokes
and shapes, and it might also contain the exact location for that instance...