Permalink
Browse files

chapter merged strings

  • Loading branch information...
1 parent be2817e commit 5c46f6fe800c9b0ef0c8c9430c513473ca00c3dc @rafiks committed Jan 1, 2013
Showing with 104 additions and 0 deletions.
  1. +26 −0 array.c
  2. BIN copychar
  3. +16 −0 copychar.c
  4. BIN digit
  5. +28 −0 digit.c
  6. BIN hello
  7. +7 −0 hello.c
  8. BIN word
  9. +27 −0 wordc.c
View
26 array.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+int main(int argc, const char *argv[])
+{
+ 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;
+ }
+ ++nother;
+ }
+ printf("digits =");
+ for (i = 0; i < 10; i++) {
+ /* code */
+ }
+ return 0;
+}
View
BIN copychar
Binary file not shown.
View
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+/* count characters in input ; 1st versin*/
+
+int main(int argc, const char *argv[])
+{
+ long nc;
+
+ nc = 0;
+
+ while (getchar() != EOF) {
+ ++nc;
+ }
+ printf("%ld\n", nc);
+ return 0;
+}
View
BIN digit
Binary file not shown.
View
28 digit.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+int main(int argc, const char *argv[])
+{
+ 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 =");
+ for (i = 0; i < 10; ++i) {
+ printf("%d", ndigit[i]);
+ }
+ printf(", white space = %d, other = %d\n", nwhite, nother);
+ return 0;
+}
View
BIN hello
Binary file not shown.
View
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, const char *argv[])
+{
+ printf("hello, world\n");
+ return 0;
+}
View
BIN word
Binary file not shown.
View
27 wordc.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+#define IN 1
+#define OUT 0
+
+int main(int argc, const char *argv[])
+{
+ int c, nl, nw, nc, state;
+
+ state = OUT;
+ nl = nw = nc = 0;
+ while ((c = getchar()) != EOF) {
+ ++nc;
+ if (c == '\n') {
+ ++nl;
+ }
+ if (c == ' ' || c == '\n' || c == '\t') {
+ state = OUT;
+ }
+ else if (state == OUT) {
+ state == IN;
+ ++nw;
+ }
+ }
+ printf("%d %d %d\n", nl, nw, nc);
+ return 0;
+}

0 comments on commit 5c46f6f

Please sign in to comment.