im writing a program that opens a file, reads until it arrives at a colon, then jumps over the colon and reads the number after the colon
the txt file contains
pi:3.14159
feetPerMile:5280
0FinDegreesC:-17.8
Count these words:3
Space before number: 2.0
What about comments: 6.024e23
so i want to skip the colons
my code
#define LINESIZE 160
#define INFILE "config.txt"
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char buf[LINESIZE];
FILE *fin;
fin = fopen(INFILE, "r");
while ( fgets ( buf, LINESIZE, fin) != NULL )
{
int i;
if (buf[i] == ':');
fputs ( buf, stdout );
sscanf(buf+i+1, "%d:");
printf("%d");
printf("\n");
}
fclose (fin);
return 0;
}
when i run i get an error message
basically i want it to eventually print out
pi
3.14159
feetPerMile
5280
0FinDegreesC
-17.8
Count these words
3
Space before number
2.0
What about comments
6.024e23