Search
 
SCRIPT & CODE EXAMPLE
 

C

printing words lemgthwise in c

#include <stdio.h>

#define SIZEOFWORDSOFLENGTH 21

int main() {
    int wordsOfLength[SIZEOFWORDSOFLENGTH];
    int c, i, j;
    int lengthCounter = 0;

    /*Initializing all array elements to 0.*/
    for (i = 0; i < SIZEOFWORDSOFLENGTH; i++)
        wordsOfLength[i] = 0;

    /*Going through the input and counting.*/
    while ((c = getchar()) != EOF) {
        ++lengthCounter;
        if (c == ' ' || c == '	' || c == '
') {
            ++wordsOfLength[lengthCounter - 1];
            lengthCounter = 0;
        }
    }

    for (i = 0; i < SIZZEOFWORDSOFLENGTH; i++) {
        printf("Words of Length %d: ", i);
        /*The third argument of the following for loop was previously j = j*/
        for (j = 0; j < SIZEOFWORDSOFLENGTH; j++) {
            while (j < wordsOfLength[i]) {
                printf("|");
                /*Was previously j++ instead of break*/
                break;
            }
        }
        printf("
");
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: C Pass Individual Array Elements 
C :: fungetc 
C :: c for result 
C :: Returns numbers between i and 0 
C :: XAudio2 C 
C :: cyrildewit laravel page view counter package. 
C :: data-types 
C :: vscode how to output in seperate consile 
C :: dev c online 
C :: semicolong after for() loop stackoverflow 
C :: c to assembly online compiler 
C :: can torch light bring change in chemical reaction 
C :: C static libraries (creating object files) 
C :: windows block application au demarrage regegit 
C :: remove every appearance of char without malloc in c 
C :: YOUNG SEX PARTY underground collection 
C :: convert char to int ascii in c function 
C :: converting time in c 
C :: fina students name by using html backend database 
C :: mettre int dans string c % 
C :: panagram in c 
C :: levenshtein c 
C :: np mean 2nd dimension 
C :: are two matrcies identical 
C :: bucket sort 
C :: fibonacchi series in c 
Dart :: flutter listtile shape border 
Dart :: python change type of elements in list 
Dart :: how to get the name of the day in flutter 
Dart :: dart ceil 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =