i want to print the line number and column number of all the occurance of a string "//" in a given input file. I am able to count the number of occurance, but not with the column number
#include <stdio.h>
int main ()
{
FILE * pFile;
int c;
int n = 0;
pFile=fopen ("testing.c","r");
if (pFile==NULL) perror ("Error opening file");
else
{
do
{
c = fgetc (pFile);
if (c == '/')
{
c = fgetc (pFile);
if (c == '/')
{
n++;
}
}
} while (c != EOF);
fclose (pFile);
printf ("The file contains %d comment characters (//).\n",n);
}
return 0;
}
*** MOD EDIT: Added code tags. Please
This post has been edited by JackOfAllTrades: 21 April 2009 - 04:45 AM

New Topic/Question
Reply




MultiQuote






|