Working with file I/O
Basically, a user inputs a file which they want read. They can enter a sentinel value of "STOP" in which case the program stops.
The program then opens the file, reads line by line until end of file, and prints each line to the console.
Little new to file I/O, so wondering if anyone could help me. Here's what I have so far:
Code:
#include <stdio.h>
#include <string.h>
int readSource (char *input);
int main() {
char input[100];
char sentinel[5] = "STOP" ;
printf("This program will count the number of functions as well as the number of source lines of code in a file.\n");
printf("\nEnter name of File: ");
gets(input);
while ((strcmp (input, sentinel) != 0)) {
readSource(input);
}
getchar();
}
int readSource (char *input) {
FILE *fp;
fp = fopen("input", "r");
if (fp == NULL)
{
// Error, file not found
}
else
{
// Process & close file
fclose(fp);
}
}