Commit 673dbacb by antsim

08.03

parent 342b5bb0
Thomas 55500077 Paldiski_45_66 Tallinn
Oleg 59428388 Kopli_3_53 Tartu
Tom 583497589 Kalev_15_25 Tallinn
Valera 57293747 Umera_55_22 Narva
Olja 55500077 Uus_66_5 Tallinn
Thomas 55500077 Paldiski_45_66 Tartu
Oleg 59428388 Kopli_3_53 Tartu
Karl 583497589 Kalev_15_25 Tallinn
Misha 5138472 Vara_7_43 Tallinn
Olja 55500077 Uus_66_5 Tallinn
Nika 5938499 Laagna_15_25 Tallinn
Miku 57293747 Mustam_55_22 Narva
Tanja 5923848 Tere_5_34 Tartu
Helga 5382748 Raud_3_54 Tallinn
Misha 5138472 Vara_7_43 Tallinn
\ No newline at end of file
Helga 5382748 Raud_3_54 Tallinn
Valera 57293747 Umera_55_22 Narva
\ No newline at end of file
Tallinn Thomas 55500077 Paldiski_45_66
Tallinn Tom 583497589 Kalev_15_25
Tallinn Olja 55500077 Uus_66_5
Tallinn Nika 5938499 Laagna_15_25
Tallinn Helga 5382748 Raud_3_54
Tallinn Misha 5138472 Vara_7_43
Tartu Oleg 59428388 Kopli_3_53
Tartu Tanja 5923848 Tere_5_34
Narva Valera 57293747 Umera_55_22
Narva Miku 57293747 Mustam_55_22
Karl 583497589 Kalev_15_25 Tallinn
Misha 5138472 Vara_7_43 Tallinn
Olja 55500077 Uus_66_5 Tallinn
Nika 5938499 Laagna_15_25 Tallinn
Helga 5382748 Raud_3_54 Tallinn
Thomas 55500077 Paldiski_45_66 Tartu
Oleg 59428388 Kopli_3_53 Tartu
Tanja 5923848 Tere_5_34 Tartu
Miku 57293747 Mustam_55_22 Narva
Valera 57293747 Umera_55_22 Narva
/**
File: HW1.c
Author: Anastassia Tšimbur
Created: 28.03.2017
Last edit: 08.03.2017
Description: IAG0582 Programming II Homework 1.
Functions for reading data from files and save sorted in another
*/
#include <stdio.h>
#include <string.h>
#define string_pikkus 20
#define massiiv 10
#define array 2
typedef struct{
char nimi[string_pikkus];
char tel[string_pikkus];
char aadress[array][string_pikkus];
} inimesed;
void readFile(inimesed fileinp[massiiv], FILE *file);
void sortingPrinting(inimesed fileinp[massiiv], FILE *file);//sorteerin erandjuhul Tallinn ja Tartu vastavalt ylesandele ja prindin kuvarile koos failiga
int main(){
inimesed isik[massiiv];
FILE *fileinp; //declare file input
FILE *fileoutp; //declare file outp
char inputFile[] = {"/Users/Anastassia/Desktop/F1.txt"}; //input file name
char outFile[] = {"/Users/Anastassia/Desktop/F2.txt"}; //output file name
fileinp = fopen(inputFile, "r");//fopen()
fileoutp = fopen(outFile, "w");//
readFile(isik, fileinp);
sortingPrinting(isik, fileoutp);
fclose(fileinp);
fclose(fileoutp);
return(0);
}
void readFile(inimesed fileinp[massiiv], FILE *file){
int i=0;
if (file == NULL) {
printf("File not found.\n");
}
while(!feof(file)){
fscanf(file, "%s %s %s %s", fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);
i++;
}
}
void sortingPrinting(inimesed fileinp[massiiv], FILE *file){
int i;
for(i=0;i<massiiv;i++){
if(!(strcmp(fileinp[i].aadress[1],"Tallinn"))){
/* printf("%s %s %s %s\n",fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);*/
fprintf(file,"%s %s %s %s\n",fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);
}
}
for(i=0;i<massiiv;i++){
if(!(strcmp(fileinp[i].aadress[1],"Tartu"))){
/* printf("%s %s %s %s\n",fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);*/
fprintf(file,"%s %s %s %s\n",fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);
}
}
for(i=0;i<massiiv;i++){
if((strcmp(fileinp[i].aadress[1],"Tallinn"))&&(strcmp(fileinp[i].aadress[1],"Tartu"))){
/* printf("%s %s %s %s\n",fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);*/
fprintf(file,"%s %s %s %s\n",fileinp[i].nimi,fileinp[i].tel,fileinp[i].aadress[0],fileinp[i].aadress[1]);
}
}
}
No preview for this file type
12.87 14.78 -45.78 48.14 -87.41 28.47 42.41 -9.47 -1.78 -4.78 17.11 -41.72 -88.11 58.41 42.41 9.26 5.88 4.18 -14.21 44.12
\ No newline at end of file
#include <stdio.h>
#include<stdlib.h>
#define array 15
void file_check(FILE *fp);
void file_out(FILE *fp);
int main(){
FILE *fp;
fp=fopen("/Users/Anastassia/Desktop/andmed.txt", "r");
file_check(fp);
file_out(fp);
fclose(fp);
return 0;
}
void file_check(FILE *fp){
if(fp){
printf("Open file\n\n");
}
if (fp == NULL) {
printf("File not found\n");
}
}
void file_out(FILE *fp){
int i=0;
float sum=0;
float arvud[15];
for(i=0;i<15;i++){
fscanf(fp, "%f", &arvud[i]);
}
for(i=0;i<15;i++){
printf("%.0f\n", arvud[i]);
}
for(i=0;i<15;i++){
sum=sum+arvud[i];
}
printf("\nSumm is %.0f\n", sum);
}
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