Advertising
- Stuff
- Friday, February 3rd, 2006 at 3:57:48pm UTC
- struct phonebook {
- char username[64];
- int code,time,region;
- };
- struct regions {
- char region[64];
- int code,used;
- };
- int phone_size,regions_size;
- struct regions *region_arr;
- struct phonebook **entry;
- int add_region (const char region[]) {
- int i,a=1;
- struct regions *temp;
- do {
- i=find_region_code(a);
- if (i==regions_size) {
- break;
- }
- a++;
- }while (i<regions_size);
- regions_size++;
- temp=(struct regions *)realloc(region_arr,regions_size*sizeof(struct regions));
- if (temp==NULL) {
- printf("MEMORY ERROR!\n");
- regions_size--;
- return;
- }
- region_arr=temp;
- region_arr[regions_size-1].used=1;
- region_arr[regions_size-1].code=a;
- strcpy(region_arr[regions_size-1].region,region);
- return(regions_size-1);
- }
- void compact_region () {
- int i,j=regions_size-1;
- struct regions *temp;
- for (i=0; ((i<regions_size) && (region_arr[i].used!=0)); i++) {
- }
- if (i<regions_size) {
- region_arr[i]=region_arr[j];
- }
- regions_size--;
- temp=(struct regions *)realloc(region_arr,regions_size*sizeof(struct regions));
- if (temp!=NULL) {
- region_arr=temp;
- }
- }
- int find_region_code (int code) {
- int i;
- for (i=0; (i<regions_size) && (region_arr[i].code!=code); i++) {
- }
- return(i);
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.