Ask Question
11 June, 18:44

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.

+1
Answers (1)
  1. 11 June, 19:42
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers