C
^cypis^ vel. SQ9JTI
Hi there,
i have a problem. I prepared bucket sorting with reading values from
file (data.txt) and saving to other file (aus.txt).
Everything is good if we talk about reading and sorting, but saving
doesn't work.
data.txt looks:
4
3
67
15
1
4
13
87
After compiling and running file aus txt lokks like this:
4011840
Where is the failure? Could anyone give me corrected source?
This is my code:
#include <iostream>
#include <conio.h>
#include <string.h>
#include <fstream.h>
//#include <stdio.h>
//using namespace std;
int readData(int numbers[10])
{
FILE *pl;
int i = 0;
pl = fopen("data.txt", "r");
if (pl == NULL)
printf("file not found");
while (1==fscanf(pl, "%d", &numbers)) {
i++;
}
return i;
}
void saveToFile(int table[10],char *name)
{
ofstream pl2;
pl2.open(name);
pl2 << table[10];
pl2.close();
}
int MAX=100;
int bucket[10];
int bucketsort(int numbers[10], int n)
{
int i, m;
i=0;
while(i<MAX) {
bucket = 0;
i=i+1;
}
i=0;
while(i<n) {
bucket[numbers] = bucket[numbers] + 1;
i=i+1;
}
m=0;
i=0;
while(i<MAX) {
while(bucket>0) {
numbers[m] = i;
m=m+1;
bucket = bucket-1;
}
i=i+1;
}
return 0;}
int main(int argc, int* argv[])
{
char file_name;
char *file="aus.txt";
int i,il;
int table[10];
ile = readData(table);
for (i = 0; i < il; i++)
printf("%d ", table);
printf("\n");
bucketsort(table, il);
for (i = 0; i < il; i++)
printf("%d ", table);
printf("\n");
saveToFile(table,file);
return 0;
}
i have a problem. I prepared bucket sorting with reading values from
file (data.txt) and saving to other file (aus.txt).
Everything is good if we talk about reading and sorting, but saving
doesn't work.
data.txt looks:
4
3
67
15
1
4
13
87
After compiling and running file aus txt lokks like this:
4011840
Where is the failure? Could anyone give me corrected source?
This is my code:
#include <iostream>
#include <conio.h>
#include <string.h>
#include <fstream.h>
//#include <stdio.h>
//using namespace std;
int readData(int numbers[10])
{
FILE *pl;
int i = 0;
pl = fopen("data.txt", "r");
if (pl == NULL)
printf("file not found");
while (1==fscanf(pl, "%d", &numbers)) {
i++;
}
return i;
}
void saveToFile(int table[10],char *name)
{
ofstream pl2;
pl2.open(name);
pl2 << table[10];
pl2.close();
}
int MAX=100;
int bucket[10];
int bucketsort(int numbers[10], int n)
{
int i, m;
i=0;
while(i<MAX) {
bucket = 0;
i=i+1;
}
i=0;
while(i<n) {
bucket[numbers] = bucket[numbers] + 1;
i=i+1;
}
m=0;
i=0;
while(i<MAX) {
while(bucket>0) {
numbers[m] = i;
m=m+1;
bucket = bucket-1;
}
i=i+1;
}
return 0;}
int main(int argc, int* argv[])
{
char file_name;
char *file="aus.txt";
int i,il;
int table[10];
ile = readData(table);
for (i = 0; i < il; i++)
printf("%d ", table);
printf("\n");
bucketsort(table, il);
for (i = 0; i < il; i++)
printf("%d ", table);
printf("\n");
saveToFile(table,file);
return 0;
}