CS 24000 Study Guide - Midterm Guide: Entry Point, Global Variable, Grep

10 views2 pages

For unlimited access to Study Guides, a Grade+ subscription is required.

CS#24000#lecture#3#review#1##
!
Arrays.!Count!occurrences!of!each!digit!in!a!text!(30/31!2!slides)!
#include <stdio.h>!
/* Count digits, whitespaces etc */
main()!{
int c, i, nwhite, nother;
int ndigit[10];!
nwhite = nother = 0;!
for (i=0; i < 10; i++) {
ndigit[i] = 0;
}
while ((c=getchar()) != EOF) {
if (c >= ‘0’ && c <=‘9’) {
ndigit[c-‘0’]++;
}
else if ( c == ‘ ‘ || c ==‘\n’ || c == ‘t’) {
nwhite++;
}
!else {
nother++; }
}!
printf(“Digits occurrence:\n”);
for (i=0; i < 10; i++) {
printf(“%d: %d\n”, i, ndigit[i]);
}
printf(“lines=%d chars=%d\n”, nl, nc);
}
#
Example:!implementing!“grep”!
Grep#is#a#UNIX#command#that#is#used#to#print#the#lines#of#a#file#that#match#a#
given#patten#
Grep#pattern#file#
lore 141 $ grep size index.html
<frame name="left" scrolling="no" noresize target="rtop"
src="c.htm">
<frame name="rtop" scrolling="no" target="rbottom"
src=".htm" noresize>
#
Megrep!implementation!(2!slides)!
/*!
* mygrep: Print the lines of a file that match a string
*!
* mygrep pattern file
!*/
#include <stdio.h>!
#define MAXLINE 1023 //define a marco
char line[MAXLINE+1]; //global variable
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class