Ask 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 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. 9 November, 03:07
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers