So far I've got the following codes, but I'm not sure how to put them into one.
This one is letting me write in the person's number and times used the internet, but after closing and reopening the program it is not allowing me to add new information - it deletes the old one and writes in new information.
Also, I'm not sure how to go to a given person's number to add to their times used the internet.
#include <stdio.h>
#include <stdlib.h>
#define MAX 81
void main()
{char number [MAX], ch;
int page; FILE *fp;
fp=fopen("servicenumber.txt","r+b");
if(fp==NULL)
{printf("File cannot be opened!\n");
exit (1);
}
printf ("Write in data or ctrl+z for end!\n");
printf ("PersonNumber:");
while (fgets(number, MAX-1,stdin)!=NULL)
{fputs(number,fp);
printf("Times used internet:");
scanf("%d", &page);
fflush(stdin);
fprintf(fp,"%d",page);
fputs("\n",fp); fputs("\n",fp);
printf("\nPersonNumber:");
}
fclose(fp);
fp=fopen("my.txt", "r+b");
if(fp==NULL)
{printf("File cannot be opened!\n");
exit(1);
}
printf("Content of the file:\n");
while(fgets (number, MAX-1,fp)!=NULL)
{fputs(number,stdout);
fscanf(fp,"%d",&page);
printf("%d", page);
ch=fgetc(fp); putchar(ch);
ch=fgetc(fp);putchar(ch);
}
fclose(fp);
}
For checking the size of the file I use the following program, but I'm not sure how to include it in the big program's code and how to have that if it gets bigger than 4MB to get an error message:
#include <iostream.h>
#include <fstream.h>
using namespace std;
int main () {
long begin,end;
ifstream myfile ("servicenumber.txt");
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();
cout << "size is: " << (end-begin) << " bytes.\n";
return 0;
}
Other things I am not sure how to do:
1. How to get the final results - how many people, how many times, how many were those with 10+ times using it,etc? It should get updated with each entry of the program.
2. Each time I compile the codes it gives me error for using the 'using namespace std;' :
Error PAGES1.CPP 3: Declaration syntax error
3. How should I order things so that the final information from (1) to be always ontop when I'm opening the file and the rest of the persons' numbers - times used internet to follow beneath it?
4. How do I devide the groups so that I know if someone is from group one and thus being allowed to use the service for more than 10 times without being included in the list for this.

New Topic/Question
Reply




MultiQuote



|