Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162003

Re: Allocate length of word vs fixed length

From Real Troll <real.troll@trolls.com>
Newsgroups comp.lang.c
Subject Re: Allocate length of word vs fixed length
Date 2021-07-20 22:15 +0000
Organization Aioe.org NNTP Server
Message-ID <sd7ie7$3mj$1@gioia.aioe.org> (permalink)
References <U3iJI.61694$VU3.5811@fx46.iad> <allocation-20210719204511@ram.dialup.fu-berlin.de>

Show all headers | View raw


>    A lot depends on what you then want to do with those words.
>
As pointed by Stefan and others, If all you need to do is to find the 
largest length of the words then a simple program such as this one will 
also work.

<========================================================================================================>

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

int main()
{
     FILE *gitFile;
     char line[32];
     int max_len = 0;
     int counter = 0;

     if ((gitFile = fopen("words_alpha.txt", "r")) == NULL)
     {
         perror("Error: No such file or directory\n");
         EXIT_FAILURE;
     }
     else
     {
         while (!feof(gitFile))
         {
             fscanf(gitFile, "%s", &line);
             if (strlen(line) > max_len)
             {
                 max_len = strlen(line);
             }
             counter += 1;
         }
     }
     printf("Largest word size is: %zu\n", max_len);
     printf("There are %d lines in the file \n", counter);

     return EXIT_SUCCESS;
}

<========================================================================================================>

In such a situation speed of loading a file is not important because you 
are trying to read each line one at a time.

I agree this is too simplistic but we don't know what exactly is the 
purpose of the program.


Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 12:50 -0400
  Re: Allocate length of word vs fixed length Bart <bc@freeuk.com> - 2021-07-19 19:01 +0100
    Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 14:29 -0400
      Re: Allocate length of word vs fixed length Bart <bc@freeuk.com> - 2021-07-19 19:49 +0100
        Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 18:01 -0400
          Re: Allocate length of word vs fixed length Bart <bc@freeuk.com> - 2021-07-19 23:25 +0100
      Re: Allocate length of word vs fixed length scott@slp53.sl.home (Scott Lurndal) - 2021-07-19 20:00 +0000
        Re: Allocate length of word vs fixed length Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-07-19 23:29 +0000
      Re: Allocate length of word vs fixed length Real Troll <real.troll@trolls.com> - 2021-07-20 00:30 +0100
        Re: Allocate length of word vs fixed length DFS <nospam@dfs.com> - 2021-07-19 20:40 -0400
          Re: Allocate length of word vs fixed length Real Troll <real.troll@trolls.com> - 2021-07-20 17:00 +0000
      Re: Allocate length of word vs fixed length Kaz Kylheku <563-365-8930@kylheku.com> - 2021-07-24 01:07 +0000
  Re: Allocate length of word vs fixed length David Brown <david.brown@hesbynett.no> - 2021-07-19 21:35 +0200
    Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 18:02 -0400
  Re: Allocate length of word vs fixed length Ike Naar <ike@rie.sdf.org> - 2021-07-19 21:11 +0000
    Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 18:03 -0400
      Re: Allocate length of word vs fixed length Ike Naar <ike@sdf.org> - 2021-07-20 05:28 +0000
  Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 18:21 -0400
    Re: Allocate length of word vs fixed length Bart <bc@freeuk.com> - 2021-07-19 23:29 +0100
      Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-19 18:40 -0400
  Re: Allocate length of word vs fixed length Peter 'Shaggy' Haywood <phaywood@alphalink.com.au> - 2021-07-20 11:44 +1000
  Re: Allocate length of word vs fixed length Real Troll <real.troll@trolls.com> - 2021-07-20 22:15 +0000
    Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-20 20:22 -0400
      Re: Allocate length of word vs fixed length dfs <nospam@dfs.com> - 2021-07-21 23:23 -0400

csiph-web