Here is my code so far: (this is by no means a complete program)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX 81
FILE *fileOpen(char fileName[]);
int readFile(FILE* inputFile);
int checkCreditCard();
int digitsOnly(char *strng);
int checkLastDigit(char *strng);
int main (void)
{
FILE *inputFile;
char fileName[MAX];
inputFile = fileOpen(fileName);
readFile(inputFile);
fclose(inputFile);
return 0;
}
FILE * fileOpen(char fileName[]) //function A
{
FILE *inputFile;
printf("Please enter a file name.\n");
scanf("%s", fileName);
inputFile = fopen(fileName, "r");
if (!inputFile){
printf("\aCould not open the input file.\n");
exit (1);
}
return inputFile;
}
int readFile(FILE* inputFile) //function B
{
char strng[MAX];
int len;
fgets(strng, sizeof(strng), inputFile);
len = strlen(strng);
if (strng[len - 1] == '\n'){
strng[len - 1] = '\0';
}
while(fgets(strng, sizeof(strng), inputFile)){
fgets(strng, len, stdin);
}
return 0;
}
-The issue is that when I run it and type in a file name and press enter, it just goes into the next line continuously, never exits the program just keeps going to the next line and looking for input. Hope that makes sense. Please help me out! I don't see the problem.