Hi,
Im a total beginner and I have to do this for school. Spent so much time wondering whats wrong with this... Thanks
No errors but doesnt work...
Code:
#include <stdio.h>
int nactiZeSouboru (FILE* vstup, int pole[]){
int i=0;
while (fscanf(vstup,"%d",&pole[i])==1)
{
i++;
}
return i;
}
void InserttSortt(int pole[], int n)
{
int i, pom, j;
for (i = 1; i < n; i++) {
pom = pole[i];
j = i;
while (j >= 0 && pole[j-1] > pom) {
pole[j] = pole[j-1];
j = j - 1;
}
pole[j + 1] = pom;
}
}
void zapisDoSouboru (FILE* vystup,int pole[],int n){
for (int i=0;i<n;i++)
{
fprintf(vystup,"%d ",pole[i]);
}
}
int main() {
FILE* f=fopen("vstup.txt", "r");
if(f==NULL){
return -1;
}
FILE* g=fopen("vystup.txt", "w");
if(g==NULL){
return -1;
}
int i=0, n, vstup, vystup, pole[1000];
nactiZeSouboru(f, pole);
InserttSortt(pole, i);
zapisDoSouboru(g, pole, n);
fclose(f);
fclose(g);
return 0;
}