Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int vektor[10];
- int szam, db = 0;
- FILE *oszthato = fopen("oszthato.bin", "wb");
- FILE *nem_oszthato = fopen("nem_oszthato.bin", "wb");
- if (oszthato == NULL || nem_oszthato == NULL) {
- printf("Hiba a fájl megnyitásakor.\n");
- return 1;
- }
- printf("Adjon meg szamokat (max 10, 0 a befejezeshez):\n");
- while (db < 10) {
- scanf("%d", &szam);
- if (szam == 0) {
- break;
- }
- vektor[db++] = szam;
- }
- for (int i = 0; i < db; i++) {
- if (vektor[i] % 3 == 0) {
- fwrite(&vektor[i], sizeof(int), 1, oszthato);
- } else {
- fwrite(&vektor[i], sizeof(int), 1, nem_oszthato);
- }
- }
- fclose(oszthato);
- fclose(nem_oszthato);
- oszthato = fopen("oszthato.bin", "rb");
- nem_oszthato = fopen("nem_oszthato.bin", "rb");
- if (oszthato == NULL || nem_oszthato == NULL) {
- printf("Hiba a fájl megnyitásakor.\n");
- return 1;
- }
- printf("Osztható 3-mal:\n");
- while (fread(&szam, sizeof(int), 1, oszthato) == 1) {
- printf("%d ", szam);
- }
- printf("\n");
- printf("Nem osztható 3-mal:\n");
- while (fread(&szam, sizeof(int), 1, nem_oszthato) == 1) {
- printf("%d ", szam);
- }
- printf("\n");
- fclose(oszthato);
- fclose(nem_oszthato);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement