Pagini recente » Cod sursa (job #2827121) | Cod sursa (job #1273160) | Cod sursa (job #965683) | newcomers_2 | Cod sursa (job #1266602)
// Fact.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0;
int j = 0;
int lungime = 0;
bool AreLitere = false;
int charcnt = 0;
int wordcnt = 0;
char *string = NULL;
FILE *TextIn = NULL;
FILE *TextOut = NULL;
string = (char*)malloc(1024 * 1024 + 1); //(string[i] <= 'a' && string[i] >= 'z') || (string[i] <= 'A' && string[i] >= 'Z')
TextIn = fopen("text.in", "rt"); //Conditie Litera
if (TextIn == NULL) {
printf("Eroare deschidere fisier intrare");
return 0;
}
TextOut = fopen("text.out", "wt");
fgets(string , 1024 * 1024 + 1, TextIn);
while (string[i] != 0) {
if ((string[i] >= 'a' && string[i] <= 'z') || (string[i] >= 'A' && string[i] <= 'Z')) {
charcnt++;
}
i++;
}
while (j < i) {
AreLitere = 0;
while (((string[j] >= 'a' && string[j] <= 'z') || (string[j] >= 'A' && string[j] <= 'Z')) && j < i) {
j++;
AreLitere = 1;
}
while (!((string[j] >= 'a' && string[j] <= 'z') || (string[j] >= 'A' && string[j] <= 'Z')) && j < i) {
j++;
}
if ( AreLitere ) {
wordcnt++;
}
}
if (wordcnt == 0) {
lungime = 0;
} else {
lungime = charcnt / wordcnt;
}
fprintf(TextOut, "%d", lungime);
fclose(TextIn);
fclose(TextOut);
free(string);
return 0;
}