Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2013 23:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5288805 to your computer and use it in GitHub Desktop.
Save anonymous/5288805 to your computer and use it in GitHub Desktop.
void write() //Pretty much whole function is self explanatory
{
char str[1000];
FILE* f = fopen("input.bin", "wb");
if(f == NULL)
{
perror("File opening error\n");
exit(1);
}
fseek(f, 0, SEEK_SET);
int i;
for (i = 0; i < size; i++)
{
fprintf(f, "%s;%s;%s;%s", foo[i].kid, foo[i].jid, foo[i].name, foo[i].time);
}
fclose(f);
}
void read(char* filename)
{
fp = fopen(filename, "rb");
int i = 0;
while (!feof(fp))
{
if (fp==NULL)
{
perror("File opening error\n");
exit(1);
}
fscanf(fp,"%[^;]; %[^;]; %20[^\;]; %18[^\;]", foo[i].kid, foo[i].jid,foo[i].name, foo[i].time); //Little edit when taking the "time string" not to cut-off after first ' '
i++;
}
size = i;
fclose(fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment