Here is my code so far: (not 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(char *strng);
int digitsOnly(char *strng);
int checkLastDigit(char *strng);
int main (void)
{
FILE *inputFile;
char fileName[MAX];
inputFile = fileOpen(fileName);
readFile(inputFile);
char *strng;
checkCreditCard(strng);
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, inputFile);
}
return 0;
}
int checkCreditCard(char* strng)// Function C
{
int strlen(char* strng);
int len;
if (len != 16)
{
return 0;
}
return 1;
digitsOnly(strng);
}
int digitsOnly(char *strng)// Function F
{
int i;
for (i=0; strng [i] != '\0'; i++){
if(!isdigit(strng[i]))
return 0;
}
return 1;
}
-When I compile it, it tells me "conflicting types for 'strlen'. I don't know how to resolve this. Please help! Let me know if you need more information. This is for a homework assignment. Thank you for your time.