Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:29:37+00:00 2026-06-12T17:29:37+00:00

(C PROGRAM) I’m trying to compile a main.c that uses a header but I’m

  • 0

(C PROGRAM) I’m trying to compile a main.c that uses a header but I’m getting the errors below.
When I don’t use the header (all methods in the main file) everything works.

In a string S, the program find all words occurrences and returns the word that appears the most.

I’m compiling using: gcc main.c

Thank you.

errors

In file included from main.c:9:0:
frequence.h:4:16: warning: useless storage class specifier in empty declaration [enabled by default]
main.c: In function ‘main’:
main.c:15:10: error: variable ‘word’ has initializer but incomplete type
main.c:15:10: warning: passing argument 1 of ‘show_all_words’ from incompatible pointer type [enabled by default]
frequence.h:6:17: note: expected ‘char *’ but argument is of type ‘char (*)[34]’
main.c:15:10: error: invalid use of undefined type ‘struct stat_mot’
main.c:15:19: error: storage size of ‘word’ isn’t known

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "frequence.h"

#define LONGUEURMAX 4

int main(char *argv[]) {
  char texte[] = ";! one two, tree foor one two !:;";
  struct stat_mot word = show_all_words(&texte);

  printf("%s : %d\n", word.word, word.frequency);

  return (EXIT_SUCCESS);
};

frequence.h

#ifndef DEF_FREQUENCE
#define DEF_FREQUENCE

typedef struct stat_mot;
int count_word(char * , char * );
struct stat_mot show_all_words(char *);

#endif

frequence.c

#include "frequence.h"

typedef struct stat_mot {
    char * word;
    int frequency;
} stat_mot;

int count_word(char * mot, char * text) {
  int n = 0;
  char *p;

  p = strstr(text, mot);  
  while (p != NULL) {
    n++;
    p = strstr(p + 1, mot);
  }  

  return n;
}

stat_mot show_all_words(char * text) {
    char * text_rw = strdup(text);
    char * p = strtok(text_rw, " .,;:-!?");

    char word_to_return[strlen(text)];
    int  word_frequence = 0;

    while (p != NULL) {
      if (strlen(p) >= 0) {
        int offset = p - text;
        int count = count_word(p, text);

        if (word_frequence < count) {
          strcpy(word_to_return, p);          
          word_frequence = count;
        }
      };

      p = strtok(NULL, " .,;:-!?");
    }

    free(text_rw);
    struct stat_mot word = { word_to_return, word_frequence };
    return word;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:29:38+00:00Added an answer on June 12, 2026 at 5:29 pm

    You must put your stat_mot structure in frequence.h.

    Additionally, main() should be declared like

    int main(int argc, char **argv)
    

    and texte should be a char *:

    int main(char *argv[])
    {
        char *texte = ";! one two, tree foor one two !:;";
        struct stat_mot word = show_all_words(texte);
    

    You also ought to include <string.h> and <stdlib.h> in frequence.c since you use strstr, strlen and free.

    In frequence.c, strlen is always greater or equal to zero, so the comparison will always be true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program is a game that uses RMI to allow users to connect to
My program uses QtNetwork to download stuff from internet. in int main() I call
Program has more than one entry point defined: 'Class.Main()'. Compile with /main to specify
Program that calculates and shows the value of (2 to the 10th power) This
program to output all 4 digit numbers where no prior digit is greater than
This program returns: package main import ( flag fmt ) func main() { num_agents
This program runs just fine, but for some reason when I ask for an
Program :main.cpp struct X { int x; }; export template <class T> T const&
My program runs fine in Netbeans, but I get the following error when I
The program I am trying to do is to simulate the mouse event of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.