This is the text the fileCauchydat contains Baron AugustinLo
This is the text the file(Cauchy.dat) contains.
(Baron Augustin-Louis Cauchy was a French mathematician reputed as a pioneer of analysis. He was one of the
first to state and prove theorems of calculus rigorously, rejecting the heuristic principle of the generality
of algebra of earlier authors. He almost singlehandedly founded complex analysis and the study of permutation
groups in abstract algebra. A profound mathematician, Cauchy had a great influence over his contemporaries and
successors. His writings range widely in mathematics and mathematical physics.
More concepts and theorems have been named for Cauchy than for any other mathematician in elasticity alone
there are sixteen concepts and theorems named for Cauchy. Cauchy was a prolific writer; he wrote approximately
eight hundred research articles and five complete textbooks.)
Q). In the file Cauchy.dat , Using C find all occurrences of the word mathematician. For reading the data from the input file, you can use the fscanf() function with the %s specifier. Utilize the string function strcmp() for string comparison
Solution
#include <stdio.h>
#include <string.h>
int main()
{
char textToSearch[] = \"mathematician\";
char buffer[15];
int wordCount = 0;
FILE *filePointer;
filePointer = fopen(\"Cauchy.dat\", \"r+\");
while(feof(filePointer)== 0){
fscanf(filePointer,\"%14[a-zA-Z]%*[^a-zA-Z]\",buffer);
if(strcmp(buffer, textToSearch) == 0) {
wordCount++;
}
}
fclose(filePointer);
printf(\"%d\", wordCount);
return 0;
}
