Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct Planina {
- char naziv[50], test[50];
- int visina;
- };
- void izbaciNazive(char *s, int n, struct Planina planina[])
- {
- char *p=s;
- while(*p!='\0') {
- if(!(*p>='0' && *p<='9')) {
- char *q=p, *r=p+1;
- while(*q++=*r++);
- } else {
- p++;
- }
- }
- planina[n].visina=atoi(s);
- }
- void izbaciVisine(char *s, int n, struct Planina planina[])
- {
- char *p=s;
- while(*p!='\0') {
- if(*p==' ' || (*p>='0' && *p<='9')) {
- char *q=p, *r=p+1;
- while(*q++=*r++);
- } else {
- p++;
- }
- }
- strcpy(planina[n].naziv, s);
- }
- int ucitaj(struct Planina p[], int visina)
- {
- int i;
- char test1[500], string[500];//, test2[500], test3[500];
- FILE *ulaz=fopen("planine.txt", "r");
- if(ulaz==NULL) {
- printf("Greska pri otvaranju datoteke planine.txt!");
- }
- i=0;
- while(fscanf(ulaz, "%[^\n]\n", test1)==1) {
- // printf("%d", prvoime(test1, test2));
- // printf("\n!%s %s %s!", test1, test2, test3);
- strcpy(string, test1);
- izbaciVisine(test1, i, p);
- izbaciNazive(string, i, p);
- //if(prvoime(test1, test2)) {
- // strcpy(p[i].naziv, test1);
- // p[i].visina=atoi(test2);
- //}
- //if(!prvoime(test1, test2)) {
- // strcpy(p[i].naziv, test2);
- // p[i].visina=atoi(test1);
- //}
- //if(prvoime(test1, test2)==2){
- // strcpy(p[i].naziv, strcat(test2, test1));
- // p[i].visina=atoi(test3);
- //}
- i++;
- }
- int vel=i;
- fclose(ulaz);
- return vel;
- }
- void zapisi(struct Planina p[], int vel)
- {
- int i;
- FILE *planine=fopen("planine.dat", "ab");
- if(planine==NULL) {
- printf("Greska pri otvaranju datoteke planine.dat!");
- }
- for(i=0; i<vel; i++) {
- fwrite(p, sizeof(struct Planina), vel, planine);
- }
- }
- int main()
- {
- struct Planina p[100];
- FILE *ulaz=fopen("planine.txt", "r");
- if(ulaz==NULL) {
- printf("Greska pri otvaranju datoteke planine.txt!");
- return 1;
- }
- ucitaj(p, 1000);
- int i=0;
- fclose(ulaz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement