A
Andy
Hi, I have a homework question, can some expert help me with this.
q.Write a program that reads a text file and reports the number of
integers and you may assume a number is defined as one or more digits
separated by one or whitespace characters or punctuations.
For example,
The amount is 5657 and the change is 55. The prices are 123 and 56.
The result:
# of integers: 4
so far I have this
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
int count = 0;
FILE *fp;
char prev;
fp = fopen("input.txt", "r");
prev = ' ';
while((ch = fgetc(fp)) != EOF)
{
prev = ch;
}
printf("# of integers: %d\n", count);
fclose(fp);
return 0;
}
q.Write a program that reads a text file and reports the number of
integers and you may assume a number is defined as one or more digits
separated by one or whitespace characters or punctuations.
For example,
The amount is 5657 and the change is 55. The prices are 123 and 56.
The result:
# of integers: 4
so far I have this
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
int count = 0;
FILE *fp;
char prev;
fp = fopen("input.txt", "r");
prev = ' ';
while((ch = fgetc(fp)) != EOF)
{
prev = ch;
}
printf("# of integers: %d\n", count);
fclose(fp);
return 0;
}