Pagini recente » Cod sursa (job #255454) | Cod sursa (job #1107473) | Cod sursa (job #3229338) | Cod sursa (job #2261976) | Cod sursa (job #1266578)
// Fact.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0;
int j = 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", "r"); //Conditie Litera
if (TextIn == NULL) {
printf("Eroare deschidere fisier intrare");
return 0;
}
TextOut = fopen("text.out", "w");
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++;
}
}
fprintf(TextOut, "%ld", charcnt / wordcnt);
free(string);
return 0;
}