Ask Question
20 August, 06:58

Write a function named iCount that counts the number of integers in a text file that only contains decimal integers. The function takes a single argument, a constant string that gives the name of the file. It returns an integer. If the specified file cannot be opened for reading, the function must return - 1. Ignore the main. c file. Write your solution in the iCount. c file.

+3
Answers (1)
  1. 20 August, 09:02
    0
    Below is the given solution

    Explanation:

    #include

    int iCount (char * fileName) {

    FILE * file;

    int num, count = 0;

    file = fopen (fileName, "r");

    if (! file) {

    return - 1;

    }

    while (fscanf (file, "%d", &num) = = 1)

    count++;

    fclose (file);

    return count;

    }

    int main (int argc, char * argv[]) {

    char filename[100];

    printf ("Enter file name: ");

    scanf ("%s", filename);

    printf ("Number of integers in file is %d/n", iCount (filename));

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function named iCount that counts the number of integers in a text file that only contains decimal integers. The function takes a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers