Click here to Skip to main content
15,844,009 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
void get_freq(char* sentence); // gets the frequency of the prepositions
○ void get_numerics(char* word); // gets numeric values from the text
○ void count_words(char* sentence); // counts the words of a sentence
○ void collect_stats(char text[]); // collects the frequencies of the prepositions
○ void report(); // prints the following on the screen

The final version is as follows, here I have to calculate the number of words and the number of sentences in separate functions, but I cannot.

What I have tried:

#include <stdio.h>
#include <stdlib.h>

void main() 
    FILE *ptr; 
    char ch; 
    int kelime=0;
    int cumle = 0;
    int in = 0;
    char fname[1];
    char* dosya = "output.txt";
    ptr = fopen(dosya, "r");
         printf("Boyle bir dosya yok"); 
          printf("  ",fname); 
                if(ch==' '||ch=='\n')
				if(kelime == ' in '){
				ch=fgetc(ptr); }
                printf("\n toplam kelime sayisi %s : %d\n",fname,kelime); 
                printf("\n cumle sayisi%s : %d",fname,cumle);	
                printf("\n in %s:%d  " ,fname,in);
Updated 2-Dec-20 21:17pm
Dave Kreskowiak 2-Dec-20 15:51pm    
...and you had a question or the description of a problem?
mehmetmsr 2-Dec-20 16:07pm    
yes, how can I write this with the functions I mentioned in the description section
Dave Kreskowiak 2-Dec-20 16:58pm    
You have to stop thinking in terms of step-by-step, or pipelining each operation all in one function.

You have to start thinking in terms of creating a data structure that holds all of the data the app is going to use, then think about functions that can do discrete operations on that data structure.

That's what this little assignment is forcing you to do.
BabyYoda 2-Dec-20 16:20pm    
Are you stuck on something specific? I'm not sure anyone is going to do all the work for you.
mehmetmsr 2-Dec-20 16:23pm    
I can write under a single function, I can get the desired outputs, but I cannot write in separate functions, I can only get the text.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having difficulty getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
Start by defining a struct that counts the items your problem says you are supposed to count. Those are words, same words, sentences, prepositions, and numbers. Here is a possible structure :
struct Counts
    int  words;
    int  samewords;
    int  sentences;
    int  prepositions;
    int  numbers;
Then write code to read the file, determine where words, numbers, and sentences are. Then you can count the various things you are supposed to count. Think about what defines the boundaries between words, numbers, and sentences. I would read each character and decide whether it is part of a word, a number, or a boundary character.

To count matching words you will have to keep track of the words you find. Are the matches of words within one sentence or within the entire file? Either way, you need a mechanism to save each word you find. I have no idea what you have learned so far so I can't tell you how to do that.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900