[sclug] Off topic C question

Patrick patrick at kirks.net
Fri Sep 22 10:11:44 UTC 2006


Hi all,

Can anyone see why this character counting program always finds zero 
characters?  Its based on an example from K&R Chapter 1 which also fails.

#include "stdio.h"

int main()
{
         /* count characters*/
         FILE *inFile;
         inFile = fopen("motd.xml", "r");
         int c = 0;
         long lc = 0;

         while ((c = getc(inFile)) != EOF)
         {
                 if (c == "l") {
                 ++lc;
                 }


         }

         printf("Typed %1d lines\n", nc);

         system("pause");

         return 0;

}


More information about the Sclug mailing list