Commit 8e22c65b by Raul.Leemet

Näited

parent 55248ef2
Showing with 167 additions and 0 deletions
#include <stdio.h>
#include <string.h>
typedef struct{
char date[9];
}dates;
int CheckFile(FILE *input);
int FileLength(FILE *input);
void GetDataFromFile(dates DateArray[],FILE *input);
void ChangeFormat(dates DateArray[],int lines);
void CheckDate(dates DateArray[],int lines);
int main()
{
char *InputFileName="kuup2evad.txt";
FILE *sisse;
int file=0;
int lines=0;
int i=0;
sisse = fopen(InputFileName, "r");
file=CheckFile(sisse);
if(file)
{
//Eelmises tunnis n2idatud kuidas tegelt v6iks k2ituda
return 0;
}
//Get the Number of lines in the document
lines=FileLength(sisse);
dates DateArray[lines];
GetDataFromFile(DateArray,sisse);
fclose(sisse);
ChangeFormat(DateArray,lines);
CheckDate(DateArray,lines);
return 0;
}
int CheckFile(FILE *input)
{
if (input == NULL)
{
printf("Could not open file \n");
return 1;
}
printf("File Open was succesful \n");
return 0;
}
int FileLength(FILE *input)
{
int lines=0;
char ch;
while((ch=fgetc(input))!=EOF)
{
if (ch=='\n') { lines++; }
}
return lines;
}
void GetDataFromFile(dates DateArray[],FILE *input)
{
int i=0;
//Set the file pointer to the begging of the file
rewind(input);
while(fscanf(input, "%s",DateArray[i].date) != EOF)
{
i++;
}
}
void ChangeFormat(dates DateArray[],int lines)
{
int i;
int j;
char buffer;
for(i=0;i<lines;i++)
{
for(j=0;j<4;j++)
{
buffer=DateArray[i].date[j];
DateArray[i].date[j]=DateArray[i].date[j+4];
DateArray[i].date[j+4]=buffer;
}
}
}
void CheckDate(dates DateArray[],int lines)
{
int i;
int bad=0;
char *EUname="EU.txt";
char *USname="US.txt";
char *notdate="notdate.txt";
FILE *EU;
FILE *US;
FILE *nodate;
EU = fopen(EUname, "w");
US = fopen(USname, "w");
nodate = fopen(notdate, "w");
for(i=0;i<lines;i++)
{
if(DateArray[i].date[0] > '0' && DateArray[i].date[0] < '3')
{
if(DateArray[i].date[0] == '1' && DateArray[i].date[1] < '9')
{
fprintf(nodate,"%s",DateArray[i].date);
}
else
{
if(DateArray[i].date[4] < '4')
{
if((DateArray[i].date[4] == '1' && DateArray[i].date[5] < '3') || (DateArray[i].date[4]=='0'&& DateArray[i].date[5] <= '9'))
{
if((DateArray[i].date[6] == '3'&& DateArray[i].date[7] < '2') || (DateArray[i].date[6] < '3' && DateArray[i].date[7] <= '9'))
{
fprintf(EU,"%s EU Okey\n",DateArray[i].date);
}
}
else if((DateArray[i].date[4] == '3'&& DateArray[i].date[5] < '2') || (DateArray[i].date[4] < '3' && DateArray[i].date[5] <= '9'))
{
if((DateArray[i].date[6] == '1' && DateArray[i].date[7] < '3') || (DateArray[i].date[6]=='0'&& DateArray[i].date[7] <= '9'))
{
fprintf(US,"%s US Okey\n",DateArray[i].date);
}
}
}
}
}
else
{
fprintf(nodate,"%s",DateArray[i].date);
bad++;
}
}
fclose(EU);
fclose(US);
fclose(nodate);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment