I am trying to use a struct in C to read in each word separately from a file to
ID: 3778533 • Letter: I
Question
I am trying to use a struct in C to read in each word separately from a file to then assign it to a pointer. With that I want to remove any puncuation and have each sentence separated when a period is found at the end of the sentence which uses a struct to keep track of the sentences to count how many sentences there are and how many words are in each sentence separately. So far I have:
#include <stdio.h>
#include <ctype.h>
int main(){
FILE *in = NULL;
char filename[20];
printf("Enter file name: ");
scanf("%s", filename);
in = fopen(filename,"r");
//checks for error opening the file
if(in == NULL)
{
printf("could not open file ");
return -1;
}
//scans in values of file sequencially
while(!feof(in)){
fscanf(in, "%s", );
}
fclose(in);
return 0;}
Explanation / Answer
Answer:
int main(){
FILE *in = NULL;
char filename[20];
int counts=1;. // count separate sentences
printf("Enter file name: ");
scanf("%s", filename);
in = fopen(filename,"r");
//checks for error opening the file
if(in == NULL)
{
printf("could not open file ");
return -1;
}
//scans in values of file sequencially
while(!feof(in)){
fscanf(in, "%s", );
}
while(ch!=fgetc(in))
{
if(ch=='.'){
counts++;
}
}
printf("number of separate sentences es is : %d",counts);
fclose(in);
return 0;}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.