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 list
- {
- char name[100];
- int start_price;
- int volume;
- int market;
- } list_t;
- int* whole_data(int st_price,int page,int CURRENT,int *length);
- int char_to_int(char*num);
- void graph_section(char *name,int shares,int st_price,int page,int CURRENT);
- void fun(int exp,int act);
- void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range);
- int Main_page();
- void insert(list_t *collect,char *Data,int pos);
- void view_stock(list_t*Data,int current,int page);
- void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range);
- void portfolio(char *Name);
- void my_Account(char *Name);
- void watch_list(char* Name);
- void stock_list(char *Name);
- void user_choice(int choice,char *Name);
- void trans_sec(char* Name);
- void updating_point();
- void userpage(char *users);
- char *int_char(int src);
- void *myThreadFun(void *id);
- int array[20]= {0};
- 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);
- }
- 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;
- }
- 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 userpage(char *users)
- {
- int max=5,select=1,loop=1;
- user_sec:
- while(loop)
- {
- if(select >6||select ==0)
- {
- select =1;
- }
- system("cls");
- updating_point();
- //system("color 04");
- printf(" Stock Guide\n\n");
- if(select ==1)
- {
- printf("-> portfolio\n");
- }
- else
- {
- printf(" portfolio\n");
- }
- if(select == 2)
- {
- printf("-> watchlist\n");
- }
- else
- {
- printf(" watchlist\n");
- }
- if(select==3)
- {
- printf("-> stock list\n");
- }
- else
- {
- printf(" stock list\n");
- }
- if(select==4)
- {
- printf("-> account\n");
- }
- else
- {
- printf(" account\n");
- }
- if(select ==5)
- {
- printf("-> Transaction Histroy\n");
- }
- else
- {
- printf(" Transaction histroy\n");
- }
- if(select==6)
- {
- printf("-> EXIT\n");
- }
- else
- {
- printf(" EXIT\n");
- }
- printf("Use the Arrow key's to move and select\n");
- int idx=0;
- for(idx=0; idx<20; idx++)
- {
- printf("%d ",array[idx]);
- }
- switch(_getch())
- {
- case 'H':
- select--;
- // goto user_sec;
- break;
- case 'P':
- select++;
- // goto user_sec;
- break;
- case 13:
- if(select!=6)
- {
- user_choice(select,users);;
- }
- else
- {
- loop=0;
- }
- break;
- }
- }
- }
- void user_choice(int choice,char *Name)
- {
- if(choice==1)
- portfolio(Name);
- else if(choice==2)
- watch_list(Name);
- else if(choice==3)
- stock_list(Name);
- else if(choice==4)
- my_Account(Name);
- else if(choice==5)
- trans_sec(Name);
- }
- void trans_sec(char* Name)
- {
- }
- void watch_list(char* Name)
- {
- }
- void stock_list(char *Name)
- {
- system("cls");
- FILE*fp;
- char x;
- list_t *collection=(list_t*)malloc(sizeof(list_t)*5);
- int i,arrow=0;
- fp=fopen("COMPANY_DATA.txt","r+");
- i=0;
- char all[10000];
- while((x = fgetc(fp)) != EOF)
- {
- all[i++] = x;
- }
- all[i] = '\0';
- int prev=4,page=0,loop=1,coin=5;
- while(loop)
- {
- system("cls");
- updating_point();
- inserting_the_data(collection,all,prev,page,i);
- inserting_the_data(collection,all,prev,page,i);
- prev=page;
- printf(" <<<<<<<<<<<<<<<<<<<Stock list>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf("COMPANY_NAME ||STARTING_PRICE || VOLUME || MARKET ||cur_price");
- printf("\n%s|%d|%d|%d|%d",collection[0].name,collection[0].start_price,collection[0].volume,collection[0].market,array[(page*5)+0]);
- if(arrow==0)printf("<-");
- printf("\n%s|%d|%d|%d|%d",collection[1].name,collection[1].start_price,collection[1].volume,collection[1].market,array[(5*page)+1]);
- if(arrow==1)printf("<-");
- printf("\n%s|%d|%d|%d|%d",collection[2].name,collection[2].start_price,collection[2].volume,collection[2].market,array[(5*page)+2]);
- if(arrow==2)printf("<-");
- printf("\n%s|%d|%d|%d|%d",collection[3].name,collection[3].start_price,collection[3].volume,collection[3].market,array[(5*page)+3]);
- if(arrow==3)printf("<-");
- printf("\n%s|%d|%d|%d|%d",collection[4].name,collection[4].start_price,collection[4].volume,collection[4].market,array[(5*page)+4]);
- if(arrow==4)printf("<-");
- printf("\nGo Back");
- if(arrow==5)printf("<-");
- x=_getch();
- switch(x)
- {
- case 72:
- arrow--;
- break;
- case 80:
- arrow++;
- break;
- case 75:
- page--;
- break;
- case 77:
- page++;
- break;
- case 13:
- if(arrow==5)
- loop=0;
- else
- view_stock(collection,arrow,page);
- }
- if(arrow>5 ||arrow<0)
- {
- arrow=0;
- }
- if(page>3 ||page<0)
- {
- page=0;
- arrow =0;
- }
- }
- }
- int calcu_eps(int capital,int shares)
- {
- int out_stan_shares=shares;
- return capital/out_stan_shares-14;
- }
- int calcu_pe(int price,int eps)
- {
- return eps/price;
- }
- int calcu_Div(int price)
- {
- int dividend_yield=7;
- return price/dividend_yield;
- }
- void view_stock(list_t*Data,int current,int page)
- {
- char x;
- int EPS,PE,Dividend,choice=0,loop=1;
- EPS=calcu_eps(Data[current].market,Data[current].volume);
- PE=calcu_pe(Data[current].start_price,EPS);
- Dividend=calcu_Div(Data[current].start_price);
- while(loop)
- {
- system("cls");
- updating_point();
- printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf("<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
- printf("\t\t\t\t\tFundamentals Analysis\n");
- printf("Name:%s \t\t\t\t",Data[current].name);
- printf("EPS:%d\n",EPS);
- printf("No.of.Shares:%d \t\t\t",Data[current].volume);
- printf("PE :%d\n",PE);
- printf("Starting price:%d\t\t\t",Data[current].start_price);
- printf("Dividend:%d\n",Dividend);
- printf("Market Capital:%d\n",Data[current].market);
- printf("Current Price:%d\n",array[(5*page)+current]);
- printf("\n\n\n");
- fun(0,choice);
- printf("View current graph\n");
- fun(1,choice);
- printf("Go back\n");
- x= _getch();
- switch(x)
- {
- case 'H':
- choice--;
- break;
- case 'P':
- choice++;
- break;
- case 13:
- if(choice==1)
- loop=0;
- else
- graph_section(Data[current].name,Data[current].volume,Data[current].start_price,page,current);
- }
- if(choice<0 ||choice>1)
- {
- choice=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,int shares,int st_price,int page,int CURRENT)
- {
- system("cls");
- char *str;
- int len,*data,pos=0,x1,x2,y1,y2;
- data=whole_data(st_price,page,CURRENT,&len);
- /*int gd = DETECT,gm;
- initgraph(&gd, &gm, "C:\\TC\\BGI");
- setcolor(YELLOW);
- rectangle(0,30,639,450);
- settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
- setcolor(WHITE);
- outtextxy(275,0,"Graph");
- /* x1=40;
- x2=x1;
- y1=450;
- y2=y1-data[pos++];
- len--;
- while(len--)
- {
- line(x1,y1,x2,y2);
- x1=x2;
- x2+=10;
- y1=y2;
- y2-=data[pos];
- }
- _getch();
- closegraph();*/
- }
- void fun(int exp,int act)
- {
- printf(space);
- if(exp==act)
- printf("->");
- else
- printf(" ");
- }
- void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range)
- {
- int idx=0,position=0;
- if(cur==0 && prev!=cur)
- {
- insert(collect,Data,cur+1);
- }
- else if(cur==1 && prev!=cur)
- {
- position=cur*5;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert(collect,Data,idx);
- }
- else if(cur==2 && prev!=cur)
- {
- position=10;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert(collect,Data,idx);
- }
- else if(cur==3 && prev!=cur)
- {
- position=15;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert(collect,Data,idx);
- }
- }
- void insert(list_t *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;
- while(Data[pos]!='#')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- collect[range].start_price=char_to_int(temp);
- idx=0;
- pos++;
- while(Data[pos]!='$')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- pos+=2;
- collect[range].volume=char_to_int(temp);
- collect[range].market=((collect[range].start_price)*(collect[range].volume))*2;
- range++;
- }
- }
- void my_Account(char *Name)
- {
- printf("My Account\n\n");
- printf("Name :%s\n",Name);
- printf("Starting Investment:50,000\n");
- // printf("Stock Value :%d",);
- }
- void portfolio(char *Name)
- {
- }
- int main()
- {
- printf("WELCOME\n");
- printf(" TO \n");
- printf(" STOCK GUIDE \n");
- printf("Press any Key\n");
- _getch();
- Main_page();
- return 0;
- }
- 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#20#500000$|satin#10#2500000$|ultratech#15#2000000$|polaris#17#250000$|Aditya vision#20#700000$|Mrf#35#1000000$|page#25#350000$|Ashok leyland#45#100000$|Tata#15#750000$|jio#40#100000$|kakatiya Cement#33#750000$|Coasboard Industries#27#500000$|Electrotham industries#21#210000$|Eichers#77#1000000$|Rana Sugar#13#500000$|Alkai Metals#39#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]= {20,10,15,17,20,35,25,45,15,40,33,27,21,77,13,39,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)
- {
- in++;
- 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++;
- }
- }
- ind_pos++;
- pthread_t tid_2;
- pthread_create(&tid_2, NULL, myThreadFun, (void*)1);
- }
- }
- int Main_page()
- {
- updating_point();
- FILE *fp;
- char choice,x;
- char users[100];
- char username[100];
- char password[100];
- int i=0;
- pthread_t tid;
- pthread_create(&tid, NULL, myThreadFun, NULL);
- main_sec:
- system("cls");
- while(1)
- {
- fflush(stdin);
- printf("Helix\n");
- printf("1)login\n");
- printf("2)signup\n");
- printf("3)exit");
- choice=_getch();
- if(choice== 49 || choice ==50 ||choice==51)
- break;
- else
- {
- printf("\nEnter valid choice\n");
- printf("press any key\n");
- _getch();
- system("cls");
- }
- }
- if(choice==49)
- {
- char x,*tempstr;
- char accountsDB[100];
- system("cls");
- printf("Login \n");
- printf("Username:");
- scanf("%s",username);
- printf("\n");
- i=0;
- while(username[i] != '\0')
- {
- users[i] = username[i];
- i++;
- }
- users[i] = '\0';
- i=0;
- printf("Password:");
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[i++] = x;
- }
- password[i] = '\0';
- i = 0;
- strcat(username, password);
- fp = fopen("PROJECT_DATA_FILE.txt","r");
- while((x = fgetc(fp)) != EOF)
- {
- accountsDB[i++] = x;
- }
- accountsDB[i] = '\0';
- fclose(fp);
- if(NULL == strstr(accountsDB, username))
- {
- printf("\n\n"space space"*Username or password is wrong");
- _getch();
- goto main_sec;
- }
- else
- {
- tempstr = strstr(accountsDB, username);
- }
- i=0;
- while(username[i]!='\0')
- {
- if(username[i]!=tempstr[i])
- break;
- i++;
- }
- if(i==strlen(username))
- {
- userpage(users);
- goto main_sec;
- }
- else
- {
- printf("\n\n*Username or password is wrong");
- _getch();
- goto main_sec;
- }
- }
- if(choice ==50)
- {
- system("cls");
- printf("Signup\n");
- printf("Username:");
- 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 main_sec;
- }
- 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("Password:");
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[i++] = x;
- }
- password[i] = '\0';
- printf("\nRe-Enter password:");
- 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\nSign up successful");
- _getch();
- goto main_sec;
- }
- else
- {
- printf("\n\n*Passwords do not match, try again");
- _getch();
- goto main_sec;
- }
- }
- else
- {
- printf("\n*Username is already taken");
- _getch();
- goto main_sec;
- }
- }
- if(choice==51)
- {
- system("cls");
- printf("Exit\n\n");
- printf("Are You Sure Want to Exit\n");
- printf("Enter y/n\n");
- x=_getch();
- if(x=='n'||x=='N')
- goto main_sec;
- else
- {
- printf("Thank u for visiting\n");
- }
- }
- }
- 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;
- }
Add Comment
Please, Sign In to add comment