Commit dd951c66 by antsim

HW

parent 89e76459
Showing with 65 additions and 0 deletions
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
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
#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;
int main(){
inimesed isik[massiiv];
int i=0;
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");//
//control if file available
if (fileinp == NULL) {
printf("File not found. \n");
}
while(!feof(fileinp)){
fscanf(fileinp, "%s %s %s %s", isik[i].nimi,isik[i].tel,isik[i].aadress[0],isik[i].aadress[1]);
i++;
}
for(i=0;i<10;i++){
if(!(strcmp(isik[i].aadress[1],"Tallinn"))){
fprintf(fileoutp,"%s %s %s %s\n",isik[i].aadress[1],isik[i].nimi,isik[i].tel,isik[i].aadress[0]);
}
}
for(i=0;i<10;i++){
if(!(strcmp(isik[i].aadress[1],"Tartu"))){
fprintf(fileoutp,"%s %s %s %s\n",isik[i].aadress[1],isik[i].nimi,isik[i].tel,isik[i].aadress[0]);
}
}
for(i=0;i<10;i++){
if((strcmp(isik[i].aadress[1],"Tallinn"))&&(strcmp(isik[i].aadress[1],"Tartu"))){
fprintf(fileoutp,"%s %s %s %s\n",isik[i].aadress[1],isik[i].nimi,isik[i].tel,isik[i].aadress[0]);
}
}
fclose(fileinp);
fclose(fileoutp);
return(0);
}
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