Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<windows.h>
- #include<pthread.h>
- #include<conio.h>
- #include<string.h>
- #include<graphics.h>
- #include<time.h>
- #define space "\t \t \t"
- static int up_price=0;
- static int ind_pos=0;
- typedef struct cmp_data
- {
- char name[100];
- char start_price[100];
- char volume[100];
- char market[100];
- } cmp_data;
- typedef struct account_details
- {
- char name[100];
- int investement;
- int available_cash;
- int stock_value;
- int total_transaction;
- } account_details;
- typedef struct user_details
- {
- char username[100];
- void *portfolio;
- void *watch_list;
- account_details *account;
- void *trans_his;
- } user_details;
- typedef struct record
- {
- char cmp_name[100];
- int no_of_share;//buyed
- char volume[100];//no of shares total present.
- int buy_price;
- char st_price[100];
- int selling_price;
- int percentage;//profit or loss gain
- char buy_time[40];
- char sell_time[40];
- char market[100];
- int pos;
- int active;
- char order_shares[100];
- int sell_cash;//recieved from shares
- int buy_cash;//given for shares;
- struct record*next;//next pointer to create new record;
- } record;
- typedef struct database
- {
- user_details* data;
- char name[100];
- struct database*next;
- } database;
- void *storage;
- int array[20]= {0};
- void graph(int value);
- int calculating_stock_value(user_details*file);
- void check_null();
- void printf_date(char*source);
- void insert_record_1(user_details*file,record *r1);
- void remove_record(user_details*file,int cur_pos);
- void insert_record(user_details*file,record *r1,record *r2);
- void sell_section(user_details*file,int cur_pos);
- void status();
- char *calculating_time();
- int check_quantity_available(char *requested,char *available);
- void updating_funds(user_details*file,int cmp_num,int shares);
- int check_funds(char *quantity,int number,long long int cash);
- int check_quantity(char *quantity);
- void buy_section(int cmp_num,user_details* file);
- void updating_point();
- void signup_page();
- void storing_data(user_details*cur_file);
- char *percent_int_char(int src);
- int* whole_data(int st_price,int page,int *length);
- void fun_graph(int *data,int len,int st_price);
- void graph_coordinates(int *prev_data,int len,int st_price);
- void view_stock(cmp_data*Data,user_details*file,int pos);
- void graph_section(char *name,char* shares,char* st_price,int page,int current);
- void *myThreadFun(void *id);
- char *int_char(int src);
- void login_page();
- void adding_to_watch_list(cmp_data*Data,int pos,user_details*file);
- void trans_sec(user_details*file);
- int char_to_int(char*num);
- void user_choice(int choice,user_details *file);
- void userpage(char *username);
- void welcome_page(char *username);
- int Main_page();
- void insert_into_record(cmp_data*collect,char *Data,int pos);
- void arrow_fun(int exp,int act);
- void printf_sec(char *data);
- void printf_name(char *name);
- int calcu_eps(char* capital,char* shares);
- int calcu_pe(char*price,int eps);
- int calcu_Div(char* price);
- COORD coord= {0,0};
- void gotoxy(int x,int y)
- {
- coord.X=x;
- coord.Y=y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
- }
- user_details* create_user_info(char *username)
- {
- user_details *rcd=(user_details*)malloc(1*sizeof(user_details));
- strcpy(rcd->username,username);
- account_details *poin=(account_details*)malloc(1*sizeof(account_details));
- strcpy(poin->name,username);
- poin->investement=500000;
- poin->available_cash=500000;
- poin->stock_value=0;
- poin->total_transaction=0;
- rcd->account=poin;
- rcd->portfolio=NULL;
- rcd->trans_his=NULL;
- rcd->watch_list=NULL;
- return rcd;
- }
- user_details* checking_user_details(char *username)
- {
- if(storage==NULL)
- {
- storage=malloc(sizeof(database));
- storage=(database*)malloc(sizeof(database));
- database*cur=(database*)storage;
- cur->next=NULL;
- strcpy(cur->name,username);
- cur->data=create_user_info(username);
- return cur->data;
- }
- database*temp=(database*)storage;
- while(temp!=NULL && (strcmp(temp->name,username)!=0))
- {
- temp=temp->next;
- }
- if(temp!=NULL)
- return temp->data;
- else
- {
- temp=(database*)storage;
- while(temp->next!=NULL)
- {
- temp=temp->next;
- }
- database*cur_1=(database*)malloc(sizeof(database));
- cur_1->next=NULL;
- strcpy(cur_1->name,username);
- cur_1->data=create_user_info(username);
- temp->next=cur_1;
- return cur_1->data;
- }
- }
- void *myThreadFun(void *id)
- {
- FILE * fp_3=fopen("Prices_list.txt","a+");
- char *str;
- time_t t;
- int random_1,idx,count=20;
- random_1 =idx=0;
- while(count--)
- {
- srand((unsigned) time(&t));
- random_1=rand()%10;
- Sleep(1000);
- if(random_1 == count)
- {
- if(random_1%2==0)
- str=int_char(random_1*2);
- else
- str=int_char(random_1*2*-1);
- }
- else
- {
- if(random_1%2!=0)
- str=int_char(random_1);
- else
- str=int_char(random_1*-1);
- }
- while(str[idx]!='\0')
- {
- fputc(str[idx],fp_3);
- idx++;
- }
- if(idx==0)
- {
- fputc('0',fp_3);
- }
- fputc('#',fp_3);
- idx=0;
- }
- fputc('$',fp_3);
- up_price++;
- fclose(fp_3);
- }
- int main()
- {
- printf("\n\n\n\n\n");
- printf(space "\tWELCOME\n");
- printf(space "\t TO \n");
- printf(space "\t HELIX \n");
- printf(space"\tPress any Key\n");
- _getch();
- pthread_t t;
- pthread_create(&t, NULL, myThreadFun, (void*)1);
- Main_page();
- return 0;
- }
- void login_page()
- {
- FILE *fp;
- updating_point();
- char x,*tempstr;
- char accountsDB[100],username[100],password[100],users[100];
- system("cls");
- printf("\n\n\n\n");
- printf(space space "<<<<<<<<<<<<<<Login>>>>>>>>>>>> \n\n");
- printf("\n\n\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
- printf("\n"space "\t\tUsername : %c %c\n",179,179);
- printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
- gotoxy(52,10);
- scanf("%s",username);
- printf("\n");
- int idx=0;
- while(username[idx] != '\0')
- {
- users[idx] = username[idx];
- idx++;
- }
- users[idx] = '\0';
- idx=0;
- printf("\n\n\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
- printf("\n"space "\t\tPassword : %c %c\n",179,179);
- printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
- gotoxy(52,16);
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[idx++] = x;
- }
- password[idx] = '\0';
- idx = 0;
- strcat(username, password);
- fp = fopen("PROJECT_DATA_FILE.txt","r");
- while((x = fgetc(fp)) != EOF)
- {
- accountsDB[idx++] = x;
- }
- accountsDB[idx] = '\0';
- fclose(fp);
- if(NULL == strstr(accountsDB, username))
- {
- printf("\n\n"space"*Username or password is wrong\n");
- goto end_login;
- }
- else
- {
- tempstr = strstr(accountsDB, username);
- }
- idx=0;
- while(username[idx]!='\0')
- {
- if(username[idx]!=tempstr[idx])
- break;
- idx++;
- }
- if(idx==strlen(username))
- {
- userpage(users);
- goto end_login;
- }
- else
- {
- printf("\n\n"space"*Username or password is wrong\n");
- end_login:
- printf(space "\n"space"press any key\n");
- _getch();
- }
- }
- void userpage(char *username)
- {
- welcome_page(username);
- user_details *file=checking_user_details(username);
- int select=1,loop=1;
- user_sec:
- system("color 03");
- while(loop)
- {
- updating_point();
- if(select>7 ||select==0)
- {
- select =1;
- }
- system("cls");
- printf("\n\n\n\n");
- printf(space "<<<HELIX GUIDE>>>\n");
- arrow_fun(1,select);
- printf("HELP\n");
- arrow_fun(2,select);
- printf("PORTFOLIO\n");
- arrow_fun(3,select);
- printf("WATCH LIST\n");
- arrow_fun(4,select);
- printf("STOCK LIST\n");
- arrow_fun(5,select);
- printf("ACCOUNT\n");
- arrow_fun(6,select);
- printf("TRANSACTION HISTROY\n");
- arrow_fun(7,select);
- printf("EXIT\n");
- printf(space"Use the Arrow key's to move and select\n");
- switch(_getch())
- {
- case 'H':
- select--;
- break;
- case 'P':
- select++;
- break;
- case 13:
- if(select!=7)
- {
- user_choice(select,file);
- }
- else
- {
- storing_data(file);
- loop=0;
- }
- break;
- }
- }
- }
- void storing_data(user_details*file)
- {
- database*cur=(database*)storage;
- while(cur!=NULL)
- {
- cur=cur->next;
- }
- _getch();
- cur=(database*)storage;
- while(strcmp(cur->name,file->username)!=0)
- {
- cur=cur->next;
- }
- cur->data=file;
- FILE *fp;
- fp=fopen("Prices_list.txt","w");
- fclose(fp);
- }
- void Help_sec(char *Name)
- {
- printf("\n");
- system("cls");
- updating_point();
- printf(space"<<<<<<<<<<<<<<<<Help_sec>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf("->Helix is an virtual Trading app\n");
- printf("->Which is based on Equity share's\n");
- printf(" <<<<Company Details>>>>>\n");
- printf("->Company Name=XYZ\n");
- printf("->Volume=No of shares available\n");
- printf("->Starting price=Starting price of each share\n");
- printf("->Market Capital=Total turn over capital of the company\n");
- printf(" <<<<<Fundamental Details>>>>>>\n");
- printf("->EPS=Earning per share\n");
- printf("->It is used to determine company stock Condition\n");
- printf("->Its supply and Demand in the market\n");
- printf("->if eps<=26 then its is consider at under value share\n");
- printf("->if eps >26 then it is consider at over value share\n");
- printf("->PE ratio=Price Earnings\n");
- printf("->It is used to determine company financial condition\n");
- printf("->If its below 14 it is consider as good\n");
- printf("->Dividend=Payed by the comapny\n");
- printf("->To those who hold there company share for long term \n");
- printf("->Min range =1 year to max=unlimited as long the company exists in the market\n");
- printf("->Graph section \n");
- printf("->It is used to show the company Finanial condition\n");
- printf("->Its previous performance ,also used to calculate the technical analysis\n");
- printf(space"Press any key\n");
- _getch();
- }
- void portfolio(user_details *file)
- {
- system("cls");
- printf("\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<portfolio>>>>>>>>>>>>>>>>>>>\n\n");
- if(file->portfolio==NULL)
- {
- printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
- printf(space " NULL || NULL || NULL || NULL \n");
- }
- else
- {
- char x='0';
- int loop=1,arrow=0,total=1,time=0;
- while(loop)
- {
- system("cls");
- updating_point();
- printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
- record *cur=(record*)file->portfolio;
- while(cur!=NULL)
- {
- arrow_fun(time,arrow);
- printf_name(cur->cmp_name);
- printf_sec(int_char(cur->no_of_share));
- printf(" %d ",array[cur->pos]);
- printf_sec(int_char(cur->buy_price));
- printf("\n");
- cur=cur->next;
- time++;
- }
- total=time;
- time=0;
- arrow_fun(total,arrow);
- printf("Go back\n");
- printf(space"Use the arrow keys");
- printf("Press Enter for selling\n");
- x=_getch();
- switch(x)
- {
- case 'H':
- arrow--;
- break;
- case 'P':
- arrow++;
- break;
- case 13:
- if(arrow==total)
- loop=0;
- else
- {
- cur=(record*)file->portfolio;
- while(cur!=NULL && arrow!=0)
- {
- cur=cur->next;
- arrow--;
- }
- sell_section(file,cur->pos);
- loop=0;
- }
- break;
- }
- if(arrow<0 ||arrow>total)
- {
- arrow=0;
- }
- }
- }
- printf(space "Press any key\n");
- _getch();
- }
- void sell_section(user_details*file,int cur_pos)
- {
- system("cls");
- record*set=(record*)file->portfolio;
- while(set->pos!=cur_pos)
- {
- set=set->next;
- }
- char quantity[100];
- int idx=0,index=0;
- set_up:
- if(idx==0)
- {
- record *r1=(record*)malloc(sizeof(record));
- record *r2=(record*)malloc(sizeof(record));
- printf(space"<<<<<<<<<<<<<<<<<Sell option>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space"COMPANY NAME:%s\n",set->cmp_name);
- printf(space"Shares:%s\n",int_char(set->no_of_share));
- printf(space"Cur_price:%d\n",array[set->pos]);
- printf(space"Enter the sell quantity :");
- scanf("%s",quantity);
- if(check_quantity(quantity)==0)
- {
- idx++;
- goto set_up;
- }
- if(check_quantity_available(quantity,int_char(set->no_of_share))==0)
- {
- idx++;
- goto set_up;
- }
- if(set->active==1)
- {
- memcpy((void*)r1,(void*)set,sizeof(record));
- r1->next=NULL;
- r1->sell_cash=0;
- set->active=0;
- memcpy((void*)r2,(void*)set,sizeof(record));
- r2->next=NULL;
- r2->selling_price=array[r2->pos];
- r2->percentage=(r2->selling_price-r2->buy_price)*r2->no_of_share;
- set->percentage=r2->percentage;
- strcpy(r2->sell_time,calculating_time());
- r2->sell_cash=char_to_int(quantity)*array[r2->pos];
- r2->no_of_share-=char_to_int(quantity);
- strcpy(r2->order_shares,quantity);
- insert_record(file,r1,r2);
- }
- else
- {
- memcpy((void*)r1,(void*)set,sizeof(record));
- r1->next=NULL;
- r1->selling_price=array[r1->pos];
- r1->percentage=(r1->selling_price-r1->buy_price)*r1->no_of_share;
- strcpy(r1->sell_time,calculating_time());
- r1->sell_cash=char_to_int(quantity)*array[r1->pos];
- r1->no_of_share-=char_to_int(quantity);
- strcpy(r1->order_shares,quantity);
- set->percentage=r1->percentage;
- r2->sell_cash=0;
- insert_record_1(file,r1);
- }
- if(set->no_of_share==char_to_int(quantity))
- {
- remove_record(file,set->pos);
- }
- else
- {
- set->no_of_share-=char_to_int(quantity);
- }
- account_details *acc=file->account;
- acc->available_cash=acc->available_cash+r1->sell_cash+r2->sell_cash;
- acc->total_transaction++;
- printf(space "Your Selling order is succesfull\n");
- printf(space "Your account balance is =%d\n",acc->available_cash);
- printf(space "profit or loss gained is=%d\n",set->percentage);
- FILE *fp;
- fp=fopen("COMPANY_DATA.txt","r");
- char data[1000],x,org_quantity[100];
- while((x = fgetc(fp)) != EOF)
- {
- data[index++] = x;
- }
- data[index]='\0';
- fclose(fp);
- index=0;
- int pos=0,start_pos=0,last_pos=0;
- while(pos<set->pos && data[index]!='\0')
- {
- if(data[index]=='$')
- {
- pos++;
- }
- index++;
- }
- pos=0;
- while(pos<=1)
- {
- if(data[index]=='#')
- {
- pos++;
- }
- index++;
- }
- pos=0;
- start_pos=index;
- while(data[index]!='$')
- {
- org_quantity[pos]=data[index++];
- pos++;
- }
- last_pos=index;
- fp=fopen("COMPANY_DATA.txt","w");
- index=0;
- while(index<start_pos)
- {
- x=data[index++];
- fputc(x,fp);
- }
- index=0;
- char *s=int_char(char_to_int(org_quantity)+char_to_int(quantity));
- while(s[index]!='\0')
- {
- x=s[index++];
- fputc(x,fp);
- }
- index=last_pos;
- while(data[index]!='\0')
- {
- x=data[index++];
- fputc(x,fp);
- }
- fclose(fp);
- }
- else
- {
- printf(space "press any key\n");
- _getch();
- }
- }
- void insert_record_1(user_details*file,record*r1)
- {
- record*cur=(record*)file->trans_his;
- while(cur->next!=NULL)
- {
- cur=cur->next;
- }
- cur->next=r1;
- }
- void remove_record(user_details*file,int cur_pos)
- {
- record *current=(record*)file->portfolio;
- record*cur_2=current;
- if(current->pos==cur_pos)
- {
- file->portfolio=current->next;
- }
- else
- {
- while(current->pos!=cur_pos)
- {
- current=current->next;
- }
- while(cur_2->next!=current)
- {
- cur_2->next=current->next;
- }
- }
- }
- void insert_record(user_details*file,record *r1,record *r2)
- {
- if(file->trans_his==NULL)
- {
- file->trans_his=malloc(sizeof(record));
- file->trans_his=r1;
- r1->next=r2;
- }
- else
- {
- record *cur=(record*)file->trans_his;
- while(cur->next!=NULL)
- {
- cur=cur->next;
- }
- cur->next=r1;
- cur=cur->next;
- cur->next=r2;
- }
- }
- void status()
- {
- printf(space"Will be added Soon\n");
- printf(space"Press any key\n");
- _getch();
- }
- void watch_list(user_details *file)
- {
- system("cls");
- printf("\n\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<Watch List>>>>>>>>>>>>>>>>>>>\n\n");
- printf("COMPANY NAME || START_PRICE || VOLUME || CUR_PRICE || MARKET CAPITAL\n\n");
- if(file->watch_list==NULL)
- {
- printf(" NULL || NULL || NULL || NULL || NULL ||\n");
- printf(space"Press any Key\n");
- _getch();
- }
- else
- {
- char x='0';
- record*cur;
- int loop=1,arrow=0,total=0,time=0;
- while(loop)
- {
- fflush(stdin);
- updating_point();
- cur=(record*)file->watch_list;
- system("cls");
- printf("COMPANY NAME || START_PRICE || VOLUME || CUR_PRICE || MARKET CAPITAL\n\n");
- while(cur!=NULL)
- {
- arrow_fun(time,arrow);
- printf_name(cur->cmp_name);
- printf_sec(cur->st_price);
- printf_sec(int_char(cur->no_of_share));
- printf(" %d ",array[cur->pos]);
- printf_sec(cur->market);
- printf("\n");
- cur=cur->next;
- time++;
- }
- total=time;
- time=0;
- arrow_fun(total,arrow);
- printf(space"Go Back\n");
- printf(space"Use the arrow keys \n");
- printf(space"Press enter to view the company details\n");
- x=_getch();
- switch(x)
- {
- case 'H':
- arrow--;
- break;
- case 'P':
- arrow++;
- break;
- case 13:
- if(arrow==total)
- {
- loop=0;
- }
- else
- {
- cmp_data*Data=(cmp_data*)malloc(sizeof(cmp_data));
- int var=arrow;
- cur=(record*)file->watch_list;
- while(var--)
- {
- cur=cur->next;
- }
- strcpy(Data->market,cur->market);
- strcpy(Data->name,cur->cmp_name);
- strcpy(Data->start_price,cur->st_price);
- strcpy(Data->volume,int_char(cur->no_of_share));
- view_stock(Data,file,cur->pos);
- }
- break;
- }
- if(arrow<0 || arrow>total)
- {
- arrow=total;
- }
- }
- }
- }
- void inserting_the_data(cmp_data *collect,char*Data,int prev,int cur)
- {
- int idx=0,position=0;
- if(cur==0 && prev!=cur)
- {
- insert_into_record(collect,Data,cur+1);
- }
- else if(cur==1 && prev!=cur)
- {
- position=cur*5;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert_into_record(collect,Data,idx);
- }
- else if(cur==2 && prev!=cur)
- {
- position=10;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert_into_record(collect,Data,idx);
- }
- else if(cur==3 && prev!=cur)
- {
- position=15;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert_into_record(collect,Data,idx);
- }
- }
- void insert_into_record(cmp_data *collect,char *Data,int pos)
- {
- int count=5,idx=0,range=0;
- char temp[100]= {0};
- while(range<count)
- {
- idx=0;
- while(Data[pos]!='#')
- {
- temp[idx++]=Data[pos];
- pos++;
- }
- temp[idx]='\0';
- pos++;
- strcpy(collect[range].name,temp);
- idx=0;
- temp[100]= {0};
- while(Data[pos]!='#')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- strcpy(collect[range].start_price,temp);
- idx=0;
- temp[100]= {0};
- pos++;
- while(Data[pos]!='$')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- pos+=2;
- strcpy(collect[range].volume,temp);
- temp[100]= {0};
- char *str=int_char((char_to_int(collect[range].start_price))*(char_to_int(collect[range].volume))*2);
- strcpy(collect[range].market,str);
- range++;
- }
- }
- void stock_list(user_details *file)
- {
- system("cls");
- FILE*fp=fopen("COMPANY_DATA.txt","r+");
- char x,cmp_details[1000];
- cmp_data *page_list =(cmp_data*)malloc(sizeof(cmp_data)*5);
- int idx=0,arrow=0;
- while((x = fgetc(fp)) != EOF)
- {
- cmp_details[idx++] = x;
- }
- cmp_details[idx] = '\0';
- int prev_page=4,cur_page=0,loop=1;
- while(loop)
- {
- system("cls");
- system("color f3");
- updating_point();
- inserting_the_data(page_list,cmp_details,prev_page,cur_page);
- prev_page=cur_page;
- printf("\n\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<Stock List>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
- printf(space"Company Name ||Starting || Cur_price || Volume || MARKET \n");
- arrow_fun(0,arrow);
- printf_name(page_list[0].name);
- printf_sec(page_list[0].start_price);
- printf("%d ",array[(5*cur_page)+0]);
- printf_sec(page_list[0].volume);
- printf_sec(page_list[0].market);
- printf("\n");
- arrow_fun(1,arrow);
- printf_name(page_list[1].name);
- printf_sec(page_list[1].start_price);
- printf("%d ",array[(5*cur_page)+1]);
- printf_sec(page_list[1].volume);
- printf_sec(page_list[1].market);
- printf("\n");
- arrow_fun(2,arrow);
- printf_name(page_list[2].name);
- printf_sec(page_list[2].start_price);
- printf("%d ",array[(5*cur_page)+2]);
- printf_sec(page_list[2].volume);
- printf_sec(page_list[2].market);
- printf("\n");
- arrow_fun(3,arrow);
- printf_name(page_list[3].name);
- printf_sec(page_list[3].start_price);
- printf("%d ",array[(5*cur_page)+3]);
- printf_sec(page_list[3].volume);
- printf_sec(page_list[3].market);
- printf("\n");
- arrow_fun(4,arrow);
- printf_name(page_list[4].name);
- printf_sec(page_list[4].start_price);
- printf("%d ",array[(5*cur_page)+4]);
- printf_sec(page_list[4].volume);
- printf_sec(page_list[4].market);
- printf("\n");
- arrow_fun(5,arrow);
- printf("BACK\n");
- printf(space "use the arrow keys to turn pages and for selecting stock\n");
- printf(space "press enter for selecting\n");
- printf("\n\n\n"space space"Page:%d\n",cur_page);
- x=_getch();
- switch(x)
- {
- case 72:
- arrow--;
- break;
- case 80:
- arrow++;
- break;
- case 75:
- cur_page--;
- break;
- case 77:
- cur_page++;
- break;
- case 13:
- if(arrow==5)
- loop=0;
- else
- {
- cmp_data* cur=(cmp_data*)malloc(sizeof(cmp_data)*1);
- strcpy(cur->name,page_list[arrow].name);
- strcpy(cur->market,page_list[arrow].market);
- strcpy(cur->start_price,page_list[arrow].start_price);
- strcpy(cur->volume,page_list[arrow].volume);
- view_stock(cur,file,(cur_page*5)+arrow);
- }
- }
- if(arrow>5 ||arrow<0)
- {
- arrow=0;
- }
- if(cur_page>3 ||cur_page<0)
- {
- cur_page=0;
- arrow =0;
- }
- }
- }
- int calcu_eps(char* capital,char* shares)
- {
- int out_stan_shares=char_to_int(shares);
- return char_to_int(capital)/out_stan_shares-14;
- }
- int calcu_pe(char*price,int eps)
- {
- return eps/char_to_int(price);
- }
- int calcu_Div(char* price)
- {
- int dividend_yield=7;
- return char_to_int(price)/dividend_yield;
- }
- void updating_point()
- {
- char Data[1000],x,max[3];
- int i,pos=0,in=0,count=0,idx=0;
- FILE *fp1,*fp;
- if((fp1=fopen("COMPANY_DATA.txt","r"))==NULL)
- {
- fp1=fopen("COMPANY_DATA.txt","w");
- char data[]="|venkys#40#500000$|satin#30#2500000$|ultratech#45#2000000$|polaris#57#250000$|Aditya vision#60#700000$|Mrf#85#1000000$|page#55#350000$|Ashok leyland#54#100000$|Tata#50#750000$|jio#40#100000$|kakatiya Cement#43#750000$|Coasboard Ind#47#500000$|Electrotham ind#61#210000$|Eichers#77#1000000$|Rana Sugar#53#500000$|Alkai Metals#49#450000$|Amazon#61#8500000$|JustDial#69#7200000$|Adobe#77#900000$|infoys#55#6500000$";
- i=0;
- while(data[i]!='\0')
- {
- x=data[i];
- fputc(x,fp1);
- i++;
- }
- fclose(fp1);
- }
- if(ind_pos==0)
- {
- int new_arr[20]= {40,30,45,57,60,85,55,54,50,40,43,47,61,77,53,49,61,69,77,55};
- for(idx=0; idx<20; idx++)
- {
- array[idx]=new_arr[idx];
- }
- }
- if(ind_pos<up_price)
- {
- fp=fopen("Prices_list.txt","a+");
- idx= pos=in=count =0;
- x='k';
- while(count<ind_pos)
- {
- x=fgetc(fp);
- if(x=='$')
- {
- count++;
- }
- }
- count=0;
- if(ind_pos!=0)
- {
- x='k';
- }
- while(x!='$')
- {
- x=fgetc(fp);
- Data[idx]=x;
- idx++;
- }
- Data[idx]='\0';
- while(in<idx)
- {
- while(Data[in]!='#' && Data[in]!='$')
- {
- max[pos++]=Data[in];
- in++;
- }
- if(Data[in]=='$')
- {
- in++;
- }
- else
- {
- if(pos==0)
- {
- max[pos++]='0';
- }
- max[pos]='\0';
- pos=0;
- array[count]+=char_to_int(max);
- count++;
- }
- in++;
- }
- ind_pos++;
- up_price=ind_pos;
- pthread_t tid_2;
- pthread_create(&tid_2, NULL, myThreadFun, (void*)1);
- }
- check_null();
- }
- void check_null()
- {
- int idx;
- for(idx=0; idx<20; idx++)
- {
- if(array[idx]<0)
- array[idx]=0;
- }
- }
- void view_stock(cmp_data*Data,user_details *file,int pos)
- {
- char x;
- int EPS,PE,Dividend,choice=0,loop=1;
- EPS=calcu_eps(Data->market,Data->volume);
- PE=calcu_pe(Data->start_price,EPS);
- Dividend=calcu_Div(Data->start_price);
- while(loop)
- {
- system("cls");
- updating_point();
- system("color 04");
- printf("\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
- printf(space"\t\t\t\t\tFundamentals Analysis\n");
- printf(space"Name:%s \t\t\t\t",Data->name);
- printf(space"EPS:%d\n",EPS);
- printf(space"No.of.Shares:%s \t\t\t",Data->volume);
- printf(space"PE :%d\n",PE);
- printf(space"Starting price:%s\t\t\t",Data->start_price);
- printf(space"Dividend:%d\n",Dividend);
- printf(space"Market Capital:%s\n",Data->market);
- printf(space"Current Price:%d\n",array[pos]);
- printf(space"\n\n\n"space);
- arrow_fun(0,choice);
- printf("View current graph\n"space);
- arrow_fun(1,choice);
- printf("Buy Option\n"space);
- arrow_fun(2,choice);
- printf("Add to / Remove from watch list\n\n"space);
- arrow_fun(3,choice);
- printf("Go back\n");
- x= _getch();
- switch(x)
- {
- case 'H':
- choice--;
- break;
- case 'P':
- choice++;
- break;
- case 13:
- if(choice==3)
- loop=0;
- else if(choice==0)
- {
- updating_point();
- graph_section(Data->name,Data->volume,Data->start_price,pos/5,pos%5);
- }
- else if(choice==1)
- {
- updating_point();
- buy_section(pos,file);
- }
- else if(choice==2)
- {
- updating_point();
- adding_to_watch_list(Data,pos,file);
- }
- }
- if(choice<0 ||choice>3)
- {
- choice=3;
- }
- }
- }
- void adding_to_watch_list(cmp_data*Data,int pos,user_details*file)
- {
- int temp=0;
- record *check=(record*)file->watch_list;
- while(check!=NULL)
- {
- if(strcmp(check->cmp_name,Data->name)==0)
- {
- temp=1;
- break;
- }
- check=check->next;
- }
- check=(record*)file->watch_list;
- if(temp==1)
- {
- if(strcmp(check->cmp_name,Data->name)==0)
- {
- file->watch_list=check->next;
- }
- else
- {
- while(strcmp(check->cmp_name,Data->name)!=0)
- {
- check=check->next;
- }
- record*prev=(record*)file->watch_list;
- while(prev->next!=check)
- {
- prev=prev->next;
- }
- if(check->next==NULL)
- {
- prev->next=NULL;
- }
- else
- {
- prev->next=check->next;
- }
- }
- gotoxy(40,11);
- printf(space"Removed from Watch list\n");
- }
- else
- {
- record*rd=(record*)malloc(sizeof(record));
- rd->pos=pos;
- strcpy(rd->cmp_name,Data->name);
- strcpy(rd->market,Data->market);
- rd->no_of_share=char_to_int(Data->volume);
- strcpy(rd->st_price,Data->start_price);
- if(file->watch_list==NULL)
- {
- file->watch_list=malloc(sizeof(record));
- file->watch_list=rd;
- }
- else
- {
- record*cur=(record*)file->watch_list;
- while(cur->next!=NULL)
- {
- cur=cur->next;
- }
- cur->next=rd;
- }
- gotoxy(40,11);
- printf(space "ADDED\n");
- }
- _getch();
- }
- void buy_section(int cmp_num,user_details*file)
- {
- int flag=0;
- system("cls");
- set_up:
- if(flag==0)
- {
- FILE *fp;
- fp=fopen("COMPANY_DATA.txt","r");
- char data[1000],x;
- int idx=0,pos=0,cur_pos=0,last_pos=0;
- while((x = fgetc(fp)) != EOF)
- {
- data[idx++] = x;
- }
- data[idx]='\0';
- fclose(fp);
- idx=0;
- while(pos<cmp_num && data[idx]!='\0')
- {
- if(data[idx]=='$')
- {
- pos++;
- }
- idx++;
- }
- pos=0;
- cur_pos=idx;
- char temp_data[100],cmp_name[100],shares[100];
- idx++;
- while(data[idx]!='$')
- {
- temp_data[pos]=data[idx++];
- pos++;
- }
- last_pos=idx;
- temp_data[pos]='\0';
- idx=pos=0;
- while(temp_data[idx]!='#')
- {
- cmp_name[idx]=temp_data[idx];
- idx++;
- }
- cmp_name[idx++]='\0';
- char str_pric[100];
- while(temp_data[idx]!='#')
- {
- str_pric[pos++]=temp_data[idx++];
- }
- str_pric[pos]='\0';
- pos=0;
- idx++;
- while(temp_data[idx]!='\0')
- {
- shares[pos]=temp_data[idx++];
- pos++;
- }
- shares[pos]='\0';
- account_details *sec;
- char quantity[100];
- sec=file->account;
- updating_point();
- system("cls");
- printf(space "<<<<<<<<<<<<<<<<<<<Buy Section>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space "Compaany Name:%s\n",cmp_name);
- printf(space "Company Shares:%s\n",shares);
- printf(space "Current Price:%d\n",array[cmp_num]);
- printf(space "Available Funds :%d\n",sec->available_cash);
- printf(space "Buy Quantity:");
- scanf("%s",quantity);
- if(check_quantity(quantity)==0)
- {
- flag++;
- goto set_up;
- }
- if(check_quantity_available(quantity,shares)==0)
- {
- flag++;
- goto set_up;
- }
- if(check_funds(quantity,cmp_num,sec->available_cash)==0)
- {
- flag++;
- goto set_up;
- }
- record *set=(record*)malloc(1*sizeof(record));
- set->buy_price=array[cmp_num];
- strcpy(set->cmp_name,cmp_name);
- set->no_of_share=char_to_int(quantity);
- strcpy(set->order_shares,quantity);
- strcpy(set->volume,shares);
- set->buy_cash=char_to_int(quantity)*array[cmp_num];
- set->next=NULL;
- set->active=1;
- set->pos=cmp_num;
- strcpy(set->buy_time,calculating_time());
- strcpy(set->st_price,str_pric);
- if(file->portfolio==NULL)
- {
- file->portfolio=malloc(sizeof(record));
- file->portfolio=set;
- }
- else
- {
- record *list=(record*)file->portfolio;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=set;
- }
- updating_funds(file,cmp_num,char_to_int(quantity));
- flag=1;
- idx=0;
- printf(space"Current cash %d\n",sec->available_cash);
- fp=fopen("Company_data.txt","w");
- while(idx<cur_pos)
- {
- x=data[idx];
- fputc(x,fp);
- idx++;
- }
- idx=0;
- fputc('|',fp);
- while(cmp_name[idx]!='\0')
- {
- x=cmp_name[idx++];
- fputc(x,fp);
- }
- idx=0;
- fputc('#',fp);
- while(str_pric[idx]!='\0')
- {
- x=str_pric[idx++];
- fputc(x,fp);
- }
- idx=0;
- fputc('#',fp);
- char *new_quantity=int_char(char_to_int(shares)-char_to_int(quantity));
- while(new_quantity[idx]!='\0')
- {
- x=new_quantity[idx++];
- fputc(x,fp);
- }
- idx=last_pos;
- while(data[idx]!='\0')
- {
- x=data[idx++];
- fputc(x,fp);
- }
- fclose(fp);
- account_details*cur=file->account;
- cur->total_transaction++;
- printf(space "Your Order is Succesfully Placed\n");
- _getch();
- }
- else
- {
- printf(space"Press any Key\n");
- _getch();
- }
- }
- char *calculating_time()
- {
- char *cur_time;
- int len=0;
- while(len!=25)
- {
- time_t t;
- time(&t);
- cur_time=ctime(&t);
- len=strlen(cur_time);
- }
- return cur_time;
- }
- int check_quantity_available(char *requested,char *available)
- {
- if(char_to_int(requested)<=char_to_int(available))
- return 1;
- else
- {
- printf(space "Requested quantity Not available\n");
- return 0;
- }
- }
- void updating_funds(user_details*file,int cmp_num,int shares)
- {
- account_details*sec=file->account;
- long long int cur=sec->available_cash;
- cur-=(array[cmp_num]*shares);
- sec->available_cash=cur;
- }
- int check_funds(char *quantity,int number,long long int cash)
- {
- long long int shares=char_to_int(quantity);
- if(shares*array[number]<cash)
- return 1;
- else
- return 0;
- }
- int check_quantity(char *quantity)
- {
- int idx=0;
- while(quantity[idx]!='\0')
- {
- if(quantity[idx]>47 && quantity[idx]<58)
- {
- idx++;
- }
- else
- {
- printf(space "Enter only Numbers\n");
- return 0;
- }
- }
- return 1;
- }
- int* whole_data(int st_price,int page,int CURRENT,int *length)
- {
- FILE *fp;
- char x='k',Data[10000],max_array[3];
- fp=fopen("Prices_list.txt","a+");
- int pos=0,index=0,new_arr[1000],price=0,var=(5*page)+CURRENT,value=0;
- while(value<ind_pos)
- {
- index=0;
- while(x!='$')
- {
- x=fgetc(fp);
- Data[index]=x;
- index++;
- }
- Data[index]='\0';
- int cur=0,low=0;
- while(cur!=var && low<index)
- {
- if(Data[low]=='#')
- {
- cur++;
- }
- low++;
- }
- cur=0;
- while(Data[low]!='#')
- {
- max_array[cur++]=Data[low];
- low++;
- }
- max_array[cur]='\0';
- int v;
- v=char_to_int(max_array);
- new_arr[value]=v;
- value++;
- pos++;
- x='k';
- }
- int *r=&value;
- *length=*r;
- return new_arr;
- }
- void graph_section(char *name,char* shares,char* st_price,int page,int CURRENT)
- {
- system("cls");
- int len,*data;
- printf("1");
- data=whole_data(char_to_int(st_price),page,CURRENT,&len);
- printf("2");
- int gd = DETECT,gm;
- initgraph(&gd, &gm, "C:\\TC\\BGI");
- setcolor(YELLOW);
- settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
- setcolor(WHITE);
- outtextxy(275,0,"Graph Section");
- outtextxy(50,20,"Name :");
- outtextxy(120,20,name);
- outtextxy(50,40,"Shares :");
- outtextxy(120,40,shares);
- outtextxy(450,40,"Cur_price :");
- outtextxy(545,40,int_char(array[(5*page)+CURRENT]));
- line(0,60,639,60);
- if(len==0)
- {
- outtextxy(10,430-char_to_int(st_price),st_price);
- line(10,430,10,430-char_to_int(st_price));
- }
- else
- {
- fun_graph(data,len,char_to_int(st_price));
- }
- line(0,430,639,430);
- outtextxy(150,440,"Press any Key");
- _getch();
- closegraph();
- }
- void fun_graph(int *data,int len,int st_price)
- {
- graph_coordinates(data,len,st_price);
- printf("1.5");
- int add=0;
- if(len<2)
- {
- add=2;
- }
- int dist =600/(len+add);
- int idx=0,range=len+1;
- char *str=int_char(st_price);
- int x1=10,x2=10,y1=430,y2=430-st_price;
- while(idx<range)
- {
- outtextxy(x2,y2,str);
- line(x1,y1,x2,y2);
- x1=x2;
- y1=y2;
- x2=x2+dist;
- y2=430-data[idx]-10;
- str=int_char(data[idx]);
- idx++;
- }
- }
- void graph_coordinates(int *prev_data,int len,int st_price)
- {
- int idx,cur=st_price;
- int *data=(int*)malloc(len*sizeof(int));
- for(idx=0; idx<len; idx++)
- {
- data[idx]=prev_data[idx];
- cur+=data[idx];
- data[idx]=cur;
- if(data[idx]<0)
- {
- data[idx]=0;
- cur=0;
- }
- }
- cur=0;
- int pos=0,diff=0;
- for(idx=0; idx<len; idx++)
- {
- if(data[idx]>360)
- {
- cur=data[idx]-360+2;
- pos=idx;
- data[idx]-=cur;
- while(pos--)
- {
- diff=data[pos+1]-data[pos];
- if(diff>=cur)
- {
- pos=0;
- }
- else
- {
- data[pos]-=cur;
- }
- }
- }
- }
- for(idx=0; idx<len; idx++)
- {
- prev_data[idx]=data[idx];
- }
- printf("1.9");
- }
- void printf_sec(char *data)
- {
- int len=strlen(data);
- printf("%s",data);
- if(len<12)
- {
- while(len<12)
- {
- printf(" ");
- len++;
- }
- }
- }
- void printf_name(char *name)
- {
- int len=strlen(name);
- printf("%s",name);
- if(len<25)
- {
- while(len<25)
- {
- printf(" ");
- len++;
- }
- }
- }
- void my_Account(user_details *file)
- {
- system("cls");
- printf("\n\n\n\n");
- updating_point();
- printf(space"<<<<<<<<<<<<<<<<<<My Account>>>>>>>>>>>>>>>>>>>\n\n");
- account_details*cur=file->account;
- int stock_value=calculating_stock_value(file);
- printf("NAME:");
- printf_name(file->username);
- printf("\nStarting Investment:%d\n",cur->investement);
- printf("balance =%d\n",cur->available_cash);
- printf("Stock Value:%d\n",stock_value);
- printf("Total Transactions=%d\n",cur->total_transaction);
- printf("Total Value=%d\n",stock_value+cur->available_cash);
- if((cur->available_cash+stock_value)>cur->investement)
- printf("PROFIT\n");
- else
- printf("LOSS\n");
- printf("press enter to see the graph\n");
- printf("press any other key to go back\n");
- if(_getch()==13)
- {
- graph(stock_value);
- }
- _getch();
- }
- void graph(int value)
- {
- int angle=0;
- if(value<500000 && value!=0)
- {
- if(value<5000)
- {
- angle=3.6;
- }
- else
- {
- angle=3.6*value/5000;
- }
- int gd=DETECT,gm,midx,midy;
- initgraph(&gd,&gm,"C:\\TC\\BGI");
- setcolor(BLUE);
- rectangle(0,40,639,450);
- settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
- setcolor(WHITE);
- outtextxy(275,10,"PIE_CHART");
- midx=getmaxx()/2;
- midy=getmaxy()/2;
- setfillstyle(4,YELLOW);
- pieslice(midx,midy,0,angle,100);
- setcolor(YELLOW);
- outtextxy(midx+100,midy-30,percent_int_char(value/5000));
- outtextxy(midx+100,midy-05,"stock _value");
- setfillstyle(6,BLUE);
- pieslice(midx,midy,angle,360,100);
- setcolor(BLUE);
- outtextxy(midx-10,340,percent_int_char(100-value/5000));
- outtextxy(midx+10,360,"CASH");
- outtextxy(midx+200,midy-25,"Press any key");
- }
- else
- {
- int gd=DETECT,gm,midx,midy;
- initgraph(&gd,&gm,"C:\\TC\\BGI");
- setcolor(BLUE);
- rectangle(0,40,639,450);
- settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
- setcolor(WHITE);
- outtextxy(275,10,"PIE_CHART");
- midx=getmaxx()/2;
- midy=getmaxy()/2;
- setfillstyle(4,BLUE);
- pieslice(midx,midy,0,360,100);
- setcolor(BLUE);
- outtextxy(midx+100,midy-30,"100%");
- outtextxy(midx+100,midy-05,"cash");
- outtextxy(midx+200,midy-25,"Press any key");
- }
- _getch();
- closegraph();
- }
- char *percent_int_char(int src)
- {
- char r,*string=(char*)malloc(100*sizeof(char));
- int n=src,j=0,temp=0;
- if(src<0)
- {
- n=n*-1;
- temp=1;
- }
- string[j++]='%';
- if(n==0)
- {
- string[j++]='0';
- }
- while(n!=0)
- {
- r=n%10;
- string[j++]=(r+48);
- n/=10;
- }
- if(temp==1)
- {
- string[j++]=45;
- }
- string[j]='\0';
- strrev(string);
- return string;
- }
- int calculating_stock_value(user_details*file)
- {
- int money=0;
- record*data=(record*)file->portfolio;
- while(data!=NULL)
- {
- money +=data->no_of_share*array[data->pos];
- data=data->next;
- }
- return money;
- }
- void user_choice(int choice,user_details* file)
- {
- if(choice==1)
- Help_sec(file->username);
- else if(choice==2)
- portfolio(file);
- else if(choice==3)
- watch_list(file);
- else if(choice==4)
- stock_list(file);
- else if(choice==5)
- my_Account(file);
- else if(choice==6)
- trans_sec(file);
- }
- void arrow_fun(int exp,int act)
- {
- if(exp==act)
- printf(space"->");
- else
- printf(space" ");
- }
- void welcome_page(char *username)
- {
- system("color f9");
- system("cls");
- printf("\n\n\n\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<<<<Welcome Page>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space "Welcome to HELIX %s\n",username);
- printf("\n");
- printf(space "If you are new to HELIX \n");
- printf(space" Go to the Help Section First\n");
- printf(space"Other's wise carry on\n");
- printf(space"Press any key\n");
- _getch();
- system("cls");
- }
- int Main_page()
- {
- FILE *fp;
- char choice,x;
- char users[100];
- char username[100];
- char password[100];
- int i=0;
- main_sec:
- while(1)
- {
- fflush(stdin);
- system("cls");
- printf("\n\n\n\n\n");
- printf(space "Helix\n");
- printf(space"1)login\n");
- printf(space"2)signup\n");
- printf(space"3)exit\n");
- printf(space"Enter Your choice\n");
- printf(space);
- choice=_getch();
- if(choice== 49 || choice ==50 ||choice==51)
- break;
- else
- {
- printf("\n"space"Enter valid choice\n");
- printf(space"press any key\n");
- _getch();
- system("cls");
- }
- }
- if(choice==49)
- {
- login_page();
- goto main_sec;
- }
- if(choice ==50)
- {
- signup_page();
- goto main_sec;
- }
- if(choice==51)
- {
- system("cls");
- printf(space"Exit\n\n");
- printf(space"Are You Sure Want to Exit\n");
- printf(space"Enter y/n\n");
- x=_getch();
- if(x=='n'||x=='N')
- goto main_sec;
- else
- {
- printf("\n"space"Thank u for visiting\n");
- }
- }
- }
- void signup_page()
- {
- FILE *fp;
- int i;
- char x,username[100],password[100];
- system("cls");
- printf("\n\n\n\n\n");
- printf(space "\t<<<<<<<<<<<<<<<<<<<Signup>>>>>>>>>>>>>>>>\n\n");
- printf("\n\n\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
- printf("\n"space "\t\tUsername : %c %c\n",179,179);
- printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
- gotoxy(52,11);
- scanf("%s",username);
- i=0;
- while((x = username[i]) != '\0')
- {
- if(x == '|' || x == '#' || x == '$')
- {
- printf("\n*Username must not contain special characters like |, #, $ etc.");
- _getch();
- goto signup_end;
- }
- i++;
- }
- char accountsDB[100];
- fp = fopen("PROJECT_DATA_FILE.txt","r");
- i = 0;
- while((x = fgetc(fp)) != EOF)
- {
- accountsDB[i++] = x;
- }
- fclose(fp);
- char temp_pass[100];
- if(NULL == strstr(accountsDB, username))
- {
- i=0;
- printf("\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
- printf("\n"space "\t\tPassword : %c %c\n",179,179);
- printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
- gotoxy(52,14);
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[i++] = x;
- }
- password[i] = '\0';
- printf("\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
- printf("\n"space "\t\tPassword : %c %c\n",179,179);
- printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
- gotoxy(52,16);
- i = 0;
- while((x = _getch()) != '\r')
- {
- printf("*");
- temp_pass[i++] = x;
- }
- temp_pass[i]='\0';
- if(strcmp(temp_pass,password)==0)
- {
- i = 0;
- fp = fopen("PROJECT_DATA_FILE.txt","a");
- fputc('|',fp);
- while((x = username[i]) != '\0')
- {
- fputc(x,fp);
- i++;
- }
- i = 0;
- while((x = password[i]) != '\0')
- {
- fputc(x,fp);
- i++;
- }
- fputc('$', fp);
- fputc('1', fp);
- fputc('#', fp);
- fputc('1', fp);
- fclose(fp);
- printf("\n\n"space space "Sign up successful\n");
- goto signup_end;
- }
- else
- {
- printf("\n\n"space space"*Passwords do not match, try again\n");
- goto signup_end;
- }
- }
- else
- {
- printf(space "\n"space"*Username is already taken\n");
- signup_end:
- printf(space "press any key\n");
- _getch();
- }
- }
- int char_to_int(char*num)
- {
- int length=strlen(num);
- int var=1;
- int i,c=0,temp;
- for(i=0; i<length; i++)
- {
- if(i==0 && num[i]==45 )
- {
- var=-1;
- }
- else
- {
- temp=(num[i]-48);
- c=c*10+temp;
- }
- }
- c=c*var;
- return c;
- }
- char *int_char(int src)
- {
- char r,*string=(char*)malloc(100*sizeof(char));
- int n=src,j=0,temp=0;
- if(src<0)
- {
- n=n*-1;
- temp=1;
- }
- if(n==0)
- {
- string[j++]='0';
- }
- while(n!=0)
- {
- r=n%10;
- string[j++]=(r+48);
- n/=10;
- }
- if(temp==1)
- {
- string[j++]=45;
- }
- string[j]='\0';
- strrev(string);
- return string;
- }
- void trans_sec(user_details* file)
- {
- system("cls");
- printf("\n\n\n\n");
- printf("<<<<<<<<<<<<<<<<<<Transaction Histroy>>>>>>>>>>>>>>>>>>>\n\n");
- printf(" COMPANY_NAME || OPTION || SHARE || PRICE || TIME || PERCENTAGE \n");
- record*cur=(record*)file->trans_his;
- if(file->trans_his==NULL)
- {
- printf(" NULL || NULL || NULL || NULL || NULL || NULL \n");
- }
- else
- {
- while(cur!=NULL)
- {
- updating_point();
- if(cur->active==1)
- {
- printf_name(cur->cmp_name);
- printf("|| BUY ||");
- printf_sec(int_char(cur->no_of_share));
- printf("||");
- printf_sec(int_char(cur->buy_price));
- printf("||");
- printf_date(cur->buy_time);
- printf("|| NULL \n");
- }
- else
- {
- printf_name(cur->cmp_name);
- printf("|| SELL ||");
- printf_sec(cur->order_shares);
- printf(" ||");
- printf_sec(int_char(cur->selling_price));
- printf("||");
- printf_date(cur->sell_time);
- printf("||");
- printf_sec(int_char(cur->percentage));
- printf("\n");
- }
- cur=cur->next;
- }
- }
- printf(space"Press any key\n");
- _getch();
- }
- void printf_date(char*source)
- {
- int idx=3;
- while(idx<10)
- {
- printf("%c",source[idx]);
- idx++;
- }
- }
Add Comment
Please, Sign In to add comment