I'm working on my final assignment for my class programming with c but I'm not getting it working.
This is my assignment:
Some computers contain a so called RAID system. This system, in essence, uses multiple places to store data. Create a program that will do just that. The input of the program should be a text file. The output should be two separate files containing every other character from the original file. Also give the possibility of entering two split files and merge them to the original file. So after running the program: The original file contains the text : ”Dutch people are tall.”. Split file 1 contains: ”Dthpol r al” Split file 2 contains: ”uc epeaetl.” Now if split file 1 would be saved on USB stick 1, and split file two would be saved on USB stick 2, you’d need half the time for saving the file! 3
This is the code I got so far but it keeps crashing. Hope you guys are able to help me.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char cUsb1;
char cUsb2;
int n;
char str[128];
FILE *ptr_readfile;
FILE *ptr_sizeoffile;
FILE *ptr_usb1;
FILE *ptr_usb2;
ptr_readfile = fopen("Dutch People.txt","r");
ptr_sizeoffile = fopen("Dutch People.txt", "r");
n = sizeof(ptr_sizeoffile);
printf("%i\n", n);
while(ptr_readfile != NULL)
{
if (ptr_readfile != EOF)
{
cUsb1 = fgetc(ptr_readfile);
printf("%c\n", cUsb1);
ptr_usb1 = fopen("USB1.txt", "w");
fwrite(cUsb1 , n , n , ptr_usb1);
if(!ptr_usb1)
{
return 1;
}
cUsb2 = fgetc(ptr_readfile);
printf("%c\n", cUsb2);
ptr_usb2 = fopen("USB2.txt", "w");
fwrite(cUsb2 , n , n , ptr_usb2);
if(!ptr_usb2)
{
return 1;
}
}
break;
}
fclose(ptr_readfile);
fclose(ptr_usb1);
fclose(ptr_usb2);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire