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]>
@@ -15,7 +15,7 @@ depcomp
install-sh
missing
stamp-h1
-
+count_lines
# files starting with a dot
.*
# except for .gitignores
@@ -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
-bin_PROGRAMS = io
+bin_PROGRAMS = io count_lines
io_SOURCES = io.c
+
+count_lines_SOURCES = count-lines.c
#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);
+}