Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

chapter merged strings

  • Loading branch information...
commit 5c46f6fe800c9b0ef0c8c9430c513473ca00c3dc 1 parent be2817e
@rafiks authored
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
16 copychar.c
@@ -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
7 hello.c
@@ -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;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.