I'm reading a C book, to learn the language, and I came across a task that I've trying to figure out for a couple of days now. Task entails to read a text file, which I've written the code for, and from the text file data I need to get the integers/numbers to later on add them together.
I'm a bit more familiar with .NET and that framework contains a IsNumeric() function that helps with this task; however, I can't seem to find something similar for C - I'm sure there's something like that.
Another thing I was thinking is to add the numbers/integers onto a VLA, but I'm back to the problem of identifying the numbers from the stream.
The format of the text file (which contains my sample data) is as follows:
Jane, Doe
8790
John, Smith
6753
Billy, King
100
Now, here's the code I use to read that text file (I've tested the code and it seems to work):
/* Open source file */
if ((file_pointer = fopen(FILENAME, "r")) == NULL)
{
printf("\n\nError reading source file [ %s ]\n\n", FILENAME);
exit(0);
}
/* Print header */
printf ("First Name\tLast Name\tNumber Grade\tLetter Grade\n");
printf ("-------------------------------------------------------------\n");
/* Read source file */
while (!feof(file_pointer))
{
/* Increment variable counter by 1 */
++counter;
/* Read file stream and assign it to file_content char variable */
file_content = fgetc(file_pointer);
printf("%c", file_content );
}
printf("/n");
/* Close source file */
fclose(file_pointer);
Obviously, this isn't the complete code, but you get an idea as to what I'm doing here.
If anyone could point me in the right direction, I would appreciate it.

New Topic/Question
Reply



MultiQuote




|