Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 41 lines (33 sloc) 0.733 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int isAlphabetic(char* str) {
if (strlen(str) < 2)
return 1;
int i;
for (i = 1; i < strlen(str); i ++) {
if (str[i] < str[i - 1])
return 0;
}
return 1;
}

int main() {

FILE* in;
in = fopen("words.txt", "r");
if (in == NULL) {
fprintf(stderr, "Cannot open words.txt.\n");
exit(1);
}

int totalcount, alphacount;

char word[100];
while (fscanf(in, "%s", word) != EOF) {
int isAlpha = isAlphabetic(word);
alphacount += isAlpha;
if (isAlpha)
printf("%s\n", word);
totalcount ++;
}

float percent = (alphacount / totalcount) * 100;
printf("\n");
printf("%d are alphabetical out of %d (%G percent).\n", alphacount, totalcount, percent);

}
Something went wrong with that request. Please try again.