Where do I start? First, I finally got count_lines to work the way I want
author[email protected] <[email protected]>
Sun, 16 May 2010 01:10:17 +0000 (16 01:10 +0000)
committer[email protected] <[email protected]>
Sun, 16 May 2010 01:10:17 +0000 (16 01:10 +0000)
it too, which is to count newlines, tabs, spaces, and characters (the name
is going to be changed later. I know that dashes are better, but for some
 reason I autotools did not like it when I tried editing a Makefile for
the first time. I also changed the arrays program so that it would be
accurate. (I did not know that the first array was zero. I also changed
.gitignore so that git would ignore the count_lines program when it gets
compiled.

Signed-off-by: Alex Stubbins <[email protected]>
.gitignore
src/arrays/arrays.c
src/io/Makefile.am
src/io/count-lines.c

index 440b414..aa4726e 100644 (file)
@@ -15,7 +15,7 @@ depcomp
 install-sh
 missing
 stamp-h1
-
+count_lines
 # files starting with a dot
 .*
 # except for .gitignores
index 0b0dec7..6f6c7d4 100644 (file)
@@ -15,11 +15,11 @@ int array[10], i;   //This creates an
                        //but we can store ten
                        //arrays in here.
 
-i = 1;         //This statement assigns
+i = 0;         //This statement assigns
                //the value of one to the
                //integer we created called i.
 
-while (i <= 10){       //This is a handy while
+while (i <= 9){        //This is a handy while
                        //loop. What it says in
                        //plain english is that
                        //as long as "i" is less
index 8a624fc..5e83b93 100644 (file)
@@ -1,3 +1,5 @@
-bin_PROGRAMS = io
+bin_PROGRAMS = io count_lines
 
 io_SOURCES = io.c
+
+count_lines_SOURCES = count-lines.c
index 9dc38b2..94a1a47 100644 (file)
@@ -1,6 +1,26 @@
 #include <stdio.h>
+
 int main(){
-double nl c i  //number of lines, charector, and counter
-for (c = getchar();
+       count_lines();
+       return 0;
 }
 
+void count_lines(){
+       int c=0, nl=0, nws=0, nc=0;
+       while ((c = getchar()) != EOF){
+               if (c == '\n'){
+                       ++nl;
+               }
+               else if (c == ' '){
+                       ++nws;
+                       ++nc;
+               }
+               else if (c == '\t'){
+                       ++nws;
+                       ++nc;
+               }
+               else
+                       ++nc;
+       }
+       printf("\nYou typed %d lines, %d spaces and tabs, and %d characters\n", nl, nws, nc);
+}