Originally Posted by
Dedalus
Hi all,
I have a file which contains some specials chars to gather one for each line. For example if the special char is $ (dollar) the file may looks like:
Code:
hello world $ hello
$ hello world
hello world hello world $
To what end? So you end up with 3 $ signs... what good is that, except to count them...
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{ int count;
int fs;
char *fb;
char *bp;
FILE *fp;
fp = fopen("filename.txt")
if (!fp)
{ printf("Fopen Error\n");
exit (1); }
fseek(fp,0,SEEK_END);
fs = ftell(fp)
fb = calloc(fs, sizeof(char));
fseek(fp,0,SEEK_SET);
if (!fb)
{ printf("Calloc error\n");
exit (1); }
fs -= fread(fb,sizeof(vhar),fs,fp);
if (fs)
{ fprintf("Fread Error\n");
exit (1); }
fclose(fp);
bp = fb;
while (bp = strchr(bp,'$'))
count++;
free(fb);
printf("I found %d\n", count);
return 0; }
That should be pretty close.