This program is meant to read in strings, calculate the average word length then printout all the strings that are greater than the average. My issue is with the function in red, i'm not sure how to call it or make it work, it doesnt like the strlen parameter nor the printf parameters. It is meant to printout all strings greater than the average length.

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

#define	STRING_LEN 80
#define ARRAY_LEN 5

void *emalloc(size_t s){
   void *result = malloc(s);
   if (NULL == result){
      fprintf(stderr, "Memory allocation failed!\n");
   return result;

void print_out(char *a, double avg, int nums, int n){
   if(n < nums){
       if(avg < strlen(a[n])){
         printf("%s", a[n]);
     }print_out(a, avg, nums, n+1);

int main(void){
   char word[STRING_LEN];
   char *wordlist[ARRAY_LEN];
   int num_words;
   double average;
   int n = 0;
   int i;
  num_words = 0;

   while(num_words < ARRAY_LEN && 1 == scanf("%79s", word)){
   wordlist[num_words] = emalloc((strlen(word) + 1) * sizeof   wordlist[0][0]);
      strcpy(wordlist[num_words], word);

   average = 0.0;
   for (i=0; i<num_words; i++){
      average += strlen(wordlist[i]);

   average = average / num_words;
   fprintf(stderr, "%f\n", average);

  print_out(wordlist, average, num_words, n);
   for (i=0; i<num_words; i++){

   return EXIT_SUCCESS;
7 Years
Discussion Span
Last Post by yellowSnow

Use code tags. [code=C]<Your code here> [/code].
Can you give us the output of the compiler? That would make answering your question alot easer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.