Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include<string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <math.h>
  7. //cest zadatak da se neka matrica cita iz tekstualne datoteke
  8. void printMatrica(int mat[][100], int m, int n) {
  9.     int i, j;
  10.     for (i = 0; i < m; i++) {
  11.         for (j = 0; j < n; j++) {
  12.             printf("%d\t", mat[i][j]);
  13.         }
  14.         printf("\n");
  15.     }
  16. }
  17. void matrica1() {
  18.     FILE* datoteka = fopen("matrica1.txt", "r");
  19.     int mat[100][100];
  20.     int brRedova;
  21.     int brKolona;
  22.     //fscanf_s(datoteka, "%d %d", &brRedova, &brKolona);
  23.     fscanf(datoteka, "%d %d", &brRedova, &brKolona);
  24.     for (int i = 0; i < brRedova; i++) {
  25.         for (int j = 0; j < brKolona; j++) {
  26.             //fscanf_s("%d,",&mat[i][j]);
  27.             fscanf(datoteka, "%d,", &mat[i][j]);
  28.         }
  29.     }
  30.     printMatrica(mat, brRedova, brKolona);
  31.     fclose(datoteka);
  32.  
  33. }
  34. void matrica2() {
  35.     FILE* datoteka = fopen("matrica1.txt", "r");
  36.     int mat[100][100];
  37.     int n = 0;
  38.     int br;
  39.  
  40.     while (fscanf(datoteka, "%d",&br)==1) {
  41.         n++;
  42.     }
  43.  
  44.     n = sqrt(n);
  45.     printf("%d", n);
  46.     rewind(datoteka);
  47.     for (int i = 0; i < n; i++) {
  48.         for (int j = 0; j < n; j++) {
  49.             fprintf(datoteka, "%d", &mat[i][j]);
  50.         }
  51.     }
  52.     fclose(datoteka);
  53.  
  54. }
  55. int jeRec(char string[]) {
  56.     if (strlen(string) < 3)
  57.     {
  58.         return 0;
  59.     }
  60.     for (int i = 0; i < strlen(string); i++) {
  61.         if (!isalpha(string[i])) {
  62.             return 0;
  63.  
  64.         }
  65.     }
  66.     return 1;
  67. }
  68. void izvuciRec() {//da se rec sastoji samo od slova i da bude najmanje tri karaktera dugacka
  69.     FILE* datoteka = fopen("ulaz.txt", "r");
  70.     char rec[100];
  71.  
  72.     while (fscanf(datoteka,"%s",&rec)==1) {
  73.         if (jeRec(rec)==1) {
  74.             printf("%s\n",rec);
  75.             printf("\n");
  76.         }
  77.  
  78.  
  79.  
  80.     }
  81.  
  82.     fclose(datoteka);
  83. }
  84. int main(void) {
  85.  
  86.     matrica1();
  87.     //matrica2();
  88.     //izvuciRec();
  89.     printf("\n\n");
  90.     system("Pause");
  91.     return 0;
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement