Guest User

code

a guest
Apr 9th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.74 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<windows.h>
  3. #include<pthread.h>
  4. #include<conio.h>
  5. #include<string.h>
  6. #include<graphics.h>
  7. #include<time.h>
  8. #define space "\t\t\t"
  9. #define ON 1
  10. #define OFF 0
  11. void doCursor(int);
  12. void newLine();
  13. void getGrString(char *);
  14. login()
  15. {
  16. system("cls");
  17. char username[80],password[80];
  18. int age;
  19. setbkcolor(BLACK);
  20. setcolor(YELLOW);
  21. settextstyle(BOLD_FONT,HORIZ_DIR,0);
  22. moveto(0,0);
  23. newLine();
  24. outtext(" LOGIN:");
  25. newLine();
  26. newLine();
  27. outtext(" NAME: ");
  28. getGrString(username);
  29. newLine();
  30. newLine();
  31. outtext(" PASSWORD: ");
  32. getGrString(username);
  33. getGrString(password);
  34. age=atoi(username);
  35. newLine();
  36. outtext("Name: ");
  37. outtext(username);
  38. ++age;
  39. sprintf(password,"%d",age);
  40. newLine();
  41. outtext("Next year, you will be ");
  42. outtext(password);
  43. newLine();
  44. outtext("Press key to exit! ");
  45. getch();
  46. closegraph();
  47. return 0;
  48. }
  49.  
  50. void newLine()
  51. {
  52. moveto(0,gety()+textheight("A"));
  53. }
  54. void getGrString(char *inputString)
  55. {
  56. int stringIndex=0;
  57. int xVal[255];
  58. char inputChar, outString[2];
  59. int oldColor;
  60. outString[1]=0;
  61. xVal[0]=getx();
  62. do
  63. {
  64. doCursor(ON);
  65. inputChar=getch();
  66. doCursor(OFF);
  67. if (inputChar==0) getch();
  68. else
  69. {
  70. if (inputChar==8) {
  71. oldColor=getcolor();
  72. --stringIndex;
  73. if (stringIndex<0) stringIndex=0;
  74. moveto(xVal[stringIndex],gety());
  75. setcolor(getbkcolor());
  76. outString[0]=inputString[stringIndex];
  77. outtext(outString);
  78. moveto(xVal[stringIndex],gety());
  79. setcolor(oldColor);
  80. }
  81. else {
  82. inputString[stringIndex]=inputChar;
  83. outString[0]=inputChar;
  84. outtext(outString);
  85. ++stringIndex;
  86. xVal[stringIndex]=getx();
  87. }
  88. }
  89. } while(inputChar!=13 && inputChar!=10);
  90. inputString[stringIndex]=0;
  91. }
  92. void doCursor(int on) {
  93. int curX,oldColor;
  94. char uBarStr[2] = { '_',0 };
  95. if (!on) {
  96. oldColor=getcolor();
  97. setcolor(getbkcolor());
  98. }
  99. curX=getx();
  100. outtext(uBarStr);
  101. moveto(curX,gety());
  102. if (!on) setcolor(oldColor);
  103. }
  104.  
  105.  
  106. static int up_price=0;
  107. static int ind_pos=0;
  108. typedef struct list
  109. {
  110. char name[100];
  111. int start_price;
  112. int volume;
  113. int market;
  114. } list_t;
  115. void dec_fun();
  116. char *int_char(int src);
  117. void inc_fun();
  118. void check_null();
  119. int* whole_data(int st_price,int page,int CURRENT,int *length);
  120. int char_to_int(char*num);
  121. void graph_section(char *name,int shares,int st_price,int page,int CURRENT);
  122. void fun(int exp,int act);
  123. void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range);
  124. int Main_page();
  125. void insert(list_t *collect,char *Data,int pos);
  126. void view_stock(list_t*Data,int current,int page);
  127. void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range);
  128. void portfolio(char *Name);
  129. void my_Account(char *Name);
  130. void watch_list(char* Name);
  131. void stock_list(char *Name);
  132. void user_choice(int choice,char *Name);
  133. void trans_sec(char* Name);
  134. void updating_point();
  135. void userpage(char *users);
  136. char *int_char(int src);
  137. void *myThreadFun(void *id);
  138. int array[20]= {0};
  139. void *myThreadFun(void *id)
  140. {
  141. FILE * fp_3=fopen("Prices_list.txt","a+");
  142. char *str;
  143. time_t t;
  144. int random_1,idx,count=20;
  145. random_1 =idx=0;
  146. while(count--)
  147. {
  148. srand((unsigned) time(&t));
  149. random_1=rand()%10;
  150. Sleep(1000);
  151. if(random_1 == count)
  152. {
  153. if(random_1%2==0)
  154. str=int_char(random_1*2);
  155. else
  156. str=int_char(random_1*2*-1);
  157. }
  158. else
  159. {
  160. if(random_1%2!=0)
  161. str=int_char(random_1);
  162. else
  163. str=int_char(random_1*-1);
  164. }
  165. while(str[idx]!='\0')
  166. {
  167. fputc(str[idx],fp_3);
  168. idx++;
  169. }
  170. if(idx==0)
  171. {
  172. fputc('0',fp_3);
  173. }
  174. fputc('#',fp_3);
  175. idx=0;
  176. }
  177. fputc('$',fp_3);
  178. up_price++;
  179. fclose(fp_3);
  180. }
  181. void userpage(char *users)
  182. {
  183. int max=5,select=1,loop=1;
  184. user_sec:
  185. while(loop)
  186. {
  187. if(select >6||select ==0)
  188. {
  189. select =1;
  190. }
  191. system("cls");
  192. updating_point();
  193. //system("color 04");
  194. printf(" Stock Guide\n\n");
  195. if(select ==1)
  196. {
  197. printf("-> portfolio\n");
  198. }
  199. else
  200. {
  201. printf(" portfolio\n");
  202. }
  203. if(select == 2)
  204. {
  205. printf("-> watchlist\n");
  206. }
  207. else
  208. {
  209. printf(" watchlist\n");
  210. }
  211. if(select==3)
  212. {
  213. printf("-> stock list\n");
  214. }
  215. else
  216. {
  217. printf(" stock list\n");
  218. }
  219. if(select==4)
  220. {
  221. printf("-> account\n");
  222. }
  223. else
  224. {
  225. printf(" account\n");
  226. }
  227. if(select ==5)
  228. {
  229. printf("-> Transaction Histroy\n");
  230. }
  231. else
  232. {
  233. printf(" Transaction histroy\n");
  234. }
  235. if(select==6)
  236. {
  237. printf("-> EXIT\n");
  238. }
  239. else
  240. {
  241. printf(" EXIT\n");
  242. }
  243. printf("Use the Arrow key's to move and select\n");
  244. int idx=0;
  245. for(idx=0; idx<20; idx++)
  246. {
  247. printf("%d ",array[idx]);
  248. }
  249. switch(_getch())
  250. {
  251. case 'H':
  252. select--;
  253. // goto user_sec;
  254. break;
  255. case 'P':
  256. select++;
  257. // goto user_sec;
  258. break;
  259. case 13:
  260. if(select!=6)
  261. {
  262. user_choice(select,users);;
  263. }
  264. else
  265. {
  266. loop=0;
  267. }
  268. break;
  269. }
  270. }
  271. }
  272. void user_choice(int choice,char *Name)
  273. {
  274. if(choice==1)
  275. portfolio(Name);
  276. else if(choice==2)
  277. watch_list(Name);
  278. else if(choice==3)
  279. stock_list(Name);
  280. else if(choice==4)
  281. my_Account(Name);
  282. else if(choice==5)
  283. trans_sec(Name);
  284. }
  285. void trans_sec(char* Name)
  286. {
  287.  
  288. }
  289. void watch_list(char* Name)
  290. {
  291.  
  292. }
  293. void stock_list(char *Name)
  294. {
  295. system("cls");
  296. FILE*fp;
  297. char x;
  298. list_t *collection=(list_t*)malloc(sizeof(list_t)*5);
  299. int i,arrow=0;
  300. fp=fopen("COMPANY_DATA.txt","r+");
  301. i=0;
  302. char all[10000];
  303. while((x = fgetc(fp)) != EOF)
  304. {
  305. all[i++] = x;
  306. }
  307. all[i] = '\0';
  308. int prev=4,page=0,loop=1,coin=5;
  309. while(loop)
  310. {
  311. system("cls");
  312. updating_point();
  313. inserting_the_data(collection,all,prev,page,i);
  314. inserting_the_data(collection,all,prev,page,i);
  315. prev=page;
  316. printf(" <<<<<<<<<<<<<<<<<<<Stock list>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
  317. printf("COMPANY_NAME ||STARTING_PRICE || VOLUME || MARKET ||cur_price");
  318. printf("\n%s|%d|%d|%d|%d",collection[0].name,collection[0].start_price,collection[0].volume,collection[0].market,array[(page*5)+0]);
  319. if(arrow==0)printf("<-");
  320. printf("\n%s|%d|%d|%d|%d",collection[1].name,collection[1].start_price,collection[1].volume,collection[1].market,array[(5*page)+1]);
  321. if(arrow==1)printf("<-");
  322. printf("\n%s|%d|%d|%d|%d",collection[2].name,collection[2].start_price,collection[2].volume,collection[2].market,array[(5*page)+2]);
  323. if(arrow==2)printf("<-");
  324. printf("\n%s|%d|%d|%d|%d",collection[3].name,collection[3].start_price,collection[3].volume,collection[3].market,array[(5*page)+3]);
  325. if(arrow==3)printf("<-");
  326. printf("\n%s|%d|%d|%d|%d",collection[4].name,collection[4].start_price,collection[4].volume,collection[4].market,array[(5*page)+4]);
  327. if(arrow==4)printf("<-");
  328. printf("\nGo Back");
  329. if(arrow==5)printf("<-");
  330. x=_getch();
  331. switch(x)
  332. {
  333. case 72:
  334. arrow--;
  335. break;
  336. case 80:
  337. arrow++;
  338. break;
  339. case 75:
  340. page--;
  341. break;
  342. case 77:
  343. page++;
  344. break;
  345. case 13:
  346. if(arrow==5)
  347. loop=0;
  348. else
  349. view_stock(collection,arrow,page);
  350. }
  351. if(arrow>5 ||arrow<0)
  352. {
  353. arrow=0;
  354. }
  355. if(page>3 ||page<0)
  356. {
  357. page=0;
  358. arrow =0;
  359. }
  360. }
  361. }
  362. int calcu_eps(int capital,int shares)
  363. {
  364. int out_stan_shares=shares;
  365. return capital/out_stan_shares-14;
  366. }
  367. int calcu_pe(int price,int eps)
  368. {
  369. return eps/price;
  370. }
  371. int calcu_Div(int price)
  372. {
  373. int dividend_yield=7;
  374. return price/dividend_yield;
  375. }
  376. void view_stock(list_t*Data,int current,int page)
  377. {
  378. char x;
  379. int EPS,PE,Dividend,choice=0,loop=1;
  380. EPS=calcu_eps(Data[current].market,Data[current].volume);
  381. PE=calcu_pe(Data[current].start_price,EPS);
  382. Dividend=calcu_Div(Data[current].start_price);
  383. while(loop)
  384. {
  385. system("cls");
  386. updating_point();
  387. printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
  388. printf("<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
  389. printf("\t\t\t\t\tFundamentals Analysis\n");
  390. printf("Name:%s \t\t\t\t",Data[current].name);
  391. printf("EPS:%d\n",EPS);
  392. printf("No.of.Shares:%d \t\t\t",Data[current].volume);
  393. printf("PE :%d\n",PE);
  394. printf("Starting price:%d\t\t\t",Data[current].start_price);
  395. printf("Dividend:%d\n",Dividend);
  396. printf("Market Capital:%d\n",Data[current].market);
  397. printf("Current Price:%d\n",array[(5*page)+current]);
  398. printf("\n\n\n");
  399. fun(0,choice);
  400. printf("View current graph\n");
  401. fun(1,choice);
  402. printf("Go back\n");
  403. x= _getch();
  404. switch(x)
  405. {
  406. case 'H':
  407. choice--;
  408. break;
  409. case 'P':
  410. choice++;
  411. break;
  412. case 13:
  413. if(choice==1)
  414. loop=0;
  415. else
  416. graph_section(Data[current].name,Data[current].volume,Data[current].start_price,page,current);
  417. }
  418. if(choice<0 ||choice>1)
  419. {
  420. choice=1;
  421. }
  422. }
  423. }
  424. int* whole_data(int st_price,int page,int CURRENT,int *length)
  425. {
  426. FILE *fp;
  427. char x='k',Data[10000],max_array[3];
  428. fp=fopen("Prices_list.txt","a+");
  429. int pos=0,index=0,new_arr[1000],price=0,var=(5*page)+CURRENT,value=0;
  430. while(value<ind_pos)
  431. {
  432. index=0;
  433. while(x!='$')
  434. {
  435. x=fgetc(fp);
  436. Data[index]=x;
  437. index++;
  438. }
  439. Data[index]='\0';
  440. int cur=0,low=0;
  441. while(cur!=var && low<index)
  442. {
  443. if(Data[low]=='#')
  444. {
  445. cur++;
  446. }
  447. low++;
  448. }
  449. cur=0;
  450. while(Data[low]!='#')
  451. {
  452. max_array[cur++]=Data[low];
  453. low++;
  454. }
  455. max_array[cur]='\0';
  456. int v;
  457. v=char_to_int(max_array);
  458. new_arr[value]=v;
  459. value++;
  460. pos++;
  461. x='k';
  462. }
  463. int *r=&value;
  464. *length=*r;
  465. return new_arr;
  466. }
  467. void graph_section(char *name,int shares,int st_price,int page,int CURRENT)
  468. {
  469. /*system("cls");
  470. char *str;
  471. int len,*data,pos=0,x1,x2,y1,y2;
  472. data=whole_data(st_price,page,CURRENT,&len);
  473. outtext("NAME :");*/
  474. int gd = DETECT,gm;
  475. //left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;
  476.  
  477. initgraph(&gd, &gm, "C:/TURBOC3/BGI");
  478. outtextxy(275,0,"Graph");
  479. outtextxy(275,20,name);
  480. outtextxy(275,40,int_char(shares));
  481. int max=0;
  482. int y,y2,b1,b2=5;
  483. int x1=0;
  484. int x2=2*x1;
  485.  
  486. while(x1<600 && x2<600)
  487. {
  488. x1=max;
  489. x2=2*max;
  490. y=400;
  491. b1=50;
  492. line(x1,b1,x2,b1);
  493.  
  494. //setfillstyle(LINE_FILL,BLUE);
  495. inc_fun();
  496. dec_fun();
  497. line(x1,y,x2,y);
  498. max++;
  499. }
  500. getch();
  501. closegraph();
  502. }
  503.  
  504. void dec_fun()
  505. {
  506. int arr[]={59,99,125,204,400};
  507. int i=0,j=0,v=4;
  508. while(v--)
  509. {
  510. line(j,arr[i],j+40,arr[i+1]);
  511. i++;
  512. j+=40;
  513. }
  514. }
  515.  
  516. void inc_fun()//increasing
  517. {
  518. int arr[]={59,99,125,204,400};
  519. int j=0,v=5;
  520. char *str;
  521. while(v--)
  522. {
  523. str=int_char(arr[v]);
  524. outtextxy(j,arr[v],str);
  525. line(j,arr[v],j+40,arr[v-1]);
  526. j+=40;
  527. }
  528.  
  529. }
  530.  
  531. char *int_char(int src)
  532. {
  533. char r,*string=(char*)malloc(100*sizeof(char));
  534. int n=src,j=0,temp=0;
  535. if(src<0)
  536. {
  537. n=n*-1;
  538. temp=1;
  539. }
  540. while(n!=0)
  541. {
  542. r=n%10;
  543. string[j++]=(r+48);
  544. n/=10;
  545. }
  546. if(temp==1)
  547. {
  548. string[j++]=43;
  549. }
  550. string[j]='\0';
  551. strrev(string);
  552. return string;
  553. }
  554.  
  555. void fun(int exp,int act)
  556. {
  557. printf(space);
  558. if(exp==act)
  559. printf("->");
  560. else
  561. printf(" ");
  562. }
  563. void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range)
  564. {
  565. int idx=0,position=0;
  566. if(cur==0 && prev!=cur)
  567. {
  568. insert(collect,Data,cur+1);
  569. }
  570. else if(cur==1 && prev!=cur)
  571. {
  572. position=cur*5;
  573. while(position--)
  574. {
  575. while(Data[idx]!='$')
  576. {
  577. idx++;
  578. }
  579. idx+=2;
  580. }
  581. insert(collect,Data,idx);
  582. }
  583. else if(cur==2 && prev!=cur)
  584. {
  585. position=10;
  586. while(position--)
  587. {
  588. while(Data[idx]!='$')
  589. {
  590. idx++;
  591. }
  592. idx+=2;
  593. }
  594. insert(collect,Data,idx);
  595. }
  596. else if(cur==3 && prev!=cur)
  597. {
  598. position=15;
  599. while(position--)
  600. {
  601. while(Data[idx]!='$')
  602. {
  603. idx++;
  604. }
  605. idx+=2;
  606. }
  607. insert(collect,Data,idx);
  608. }
  609. }
  610. void insert(list_t *collect,char *Data,int pos)
  611. {
  612. int count=5,idx=0,range=0;
  613. char temp[100]= {0};
  614. while(range<count)
  615. {
  616. idx=0;
  617. while(Data[pos]!='#')
  618. {
  619. temp[idx++]=Data[pos];
  620. pos++;
  621. }
  622. temp[idx]='\0';
  623. pos++;
  624. strcpy(collect[range].name,temp);
  625. idx=0;
  626. while(Data[pos]!='#')
  627. {
  628. temp[idx]=Data[pos++];
  629. idx++;
  630. }
  631. temp[idx]='\0';
  632. collect[range].start_price=char_to_int(temp);
  633. idx=0;
  634. pos++;
  635. while(Data[pos]!='$')
  636. {
  637. temp[idx]=Data[pos++];
  638. idx++;
  639. }
  640. temp[idx]='\0';
  641. pos+=2;
  642. collect[range].volume=char_to_int(temp);
  643. collect[range].market=((collect[range].start_price)*(collect[range].volume))*2;
  644. range++;
  645. }
  646. }
  647. void my_Account(char *Name)
  648. {
  649. printf("My Account\n\n");
  650. printf("Name :%s\n",Name);
  651. printf("Starting Investment:50,000\n");
  652. // printf("Stock Value :%d",);
  653.  
  654. }
  655. void portfolio(char *Name)
  656. {
  657.  
  658. }
  659. int main()
  660. {
  661. int gdriver = DETECT, gmode, errorcode;
  662. initgraph(&gdriver, &gmode, "");
  663. errorcode = graphresult();
  664. if (errorcode != grOk) /* an error occurred */
  665. {
  666. printf("Graphics error: %s\n", grapherrormsg(errorcode));
  667. printf("Press any key to halt:");
  668. getch();
  669. return(1);
  670. }
  671. setbkcolor(BLACK);
  672. setcolor(YELLOW);
  673. settextstyle(BOLD_FONT,HORIZ_DIR,0);
  674. outtextxy(254,75,"WELCOME");
  675. newLine();
  676. outtextxy(310,130,"TO");
  677. newLine();
  678. outtextxy(225,175,"STOCK GUIDE");
  679. newLine();
  680. settextstyle(BOLD_FONT,HORIZ_DIR,1);
  681. outtextxy(240,300,"Press any Key\n");
  682. getch();
  683. login();
  684. //Main_page();
  685. closegraph();
  686. return 0;
  687. }
  688. void updating_point()
  689. {
  690. char Data[1000],x,max[3];
  691. int i,pos=0,in=0,count=0,idx=0;
  692. FILE *fp1,*fp;
  693. if((fp1=fopen("COMPANY_DATA.txt","r"))==NULL)
  694. {
  695. fp1=fopen("COMPANY_DATA.txt","w");
  696. 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$";
  697. i=0;
  698. while(data[i]!='\0')
  699. {
  700. x=data[i];
  701. fputc(x,fp1);
  702. i++;
  703. }
  704. fclose(fp1);
  705.  
  706. }
  707. if(ind_pos==0)
  708. {
  709. int new_arr[20]= {20,10,15,17,20,35,25,45,15,40,33,27,21,77,13,39,61,69,77,55};
  710. for(idx=0; idx<20; idx++)
  711. {
  712. array[idx]=new_arr[idx];
  713. }
  714. }
  715. if(ind_pos<up_price)
  716. {
  717. fp=fopen("Prices_list.txt","a+");
  718. idx= pos=in=count =0;
  719. x='k';
  720. while(count<ind_pos)
  721. {
  722. x=fgetc(fp);
  723. if(x=='$')
  724. {
  725. count++;
  726. }
  727. }
  728. count=0;
  729. if(ind_pos!=0)
  730. {
  731. x='k';
  732. }
  733. while(x!='$')
  734. {
  735. x=fgetc(fp);
  736. Data[idx]=x;
  737. idx++;
  738. }
  739. Data[idx]='\0';
  740. while(in<idx)
  741. {
  742. in++;
  743. while(Data[in]!='#' && Data[in]!='$')
  744. {
  745. max[pos++]=Data[in];
  746. in++;
  747. }
  748. if(Data[in]=='$')
  749. {
  750. in++;
  751. }
  752. else
  753. {
  754. if(pos==0)
  755. {
  756. max[pos++]='0';
  757. }
  758. max[pos]='\0';
  759. pos=0;
  760. array[count]+=char_to_int(max);
  761. count++;
  762. }
  763. }
  764. ind_pos++;
  765. pthread_t tid_2;
  766. pthread_create(&tid_2, NULL, myThreadFun, (void*)1);
  767. check_null();
  768. }
  769. }
  770. void check_null()
  771. {
  772. int idx;
  773. for(idx=0;idx<20;idx++)
  774. {
  775. if(array[idx]<0)
  776. {
  777. array[idx]=0;
  778. }
  779. }
  780. }
  781. int Main_page()
  782. {
  783. updating_point();
  784. FILE *fp;
  785. char choice,x;
  786. char users[100];
  787. char username[100];
  788. char password[100];
  789. int i=0;
  790. pthread_t tid;
  791. pthread_create(&tid, NULL, myThreadFun, NULL);
  792. main_sec:
  793. system("cls");
  794. while(1)
  795. {
  796. fflush(stdin);
  797. printf("Helix\n");
  798. printf("1)login\n");
  799. printf("2)signup\n");
  800. printf("3)exit");
  801. choice=_getch();
  802. if(choice== 49 || choice ==50 ||choice==51)
  803. break;
  804. else
  805. {
  806. printf("\nEnter valid choice\n");
  807. printf("press any key\n");
  808. _getch();
  809. system("cls");
  810. }
  811. }
  812. if(choice==49)
  813. {
  814. char x,*tempstr;
  815. char accountsDB[100];
  816. system("cls");
  817. printf("Login \n");
  818. printf("Username:");
  819. scanf("%s",username);
  820. printf("\n");
  821. i=0;
  822. while(username[i] != '\0')
  823. {
  824. users[i] = username[i];
  825. i++;
  826. }
  827. users[i] = '\0';
  828. i=0;
  829. printf("Password:");
  830. while ((x = _getch()) != '\r')
  831. {
  832. printf("*");
  833. password[i++] = x;
  834. }
  835. password[i] = '\0';
  836. i = 0;
  837. strcat(username, password);
  838. fp = fopen("PROJECT_DATA_FILE.txt","r");
  839. while((x = fgetc(fp)) != EOF)
  840. {
  841. accountsDB[i++] = x;
  842. }
  843. accountsDB[i] = '\0';
  844. fclose(fp);
  845. if(NULL == strstr(accountsDB, username))
  846. {
  847. printf("\n\n"space space"*Username or password is wrong");
  848. _getch();
  849. goto main_sec;
  850. }
  851. else
  852. {
  853. tempstr = strstr(accountsDB, username);
  854. }
  855. i=0;
  856. while(username[i]!='\0')
  857. {
  858. if(username[i]!=tempstr[i])
  859. break;
  860.  
  861. i++;
  862. }
  863. if(i==strlen(username))
  864. {
  865. userpage(users);
  866. goto main_sec;
  867. }
  868. else
  869. {
  870. printf("\n\n*Username or password is wrong");
  871. _getch();
  872. goto main_sec;
  873. }
  874. }
  875. if(choice ==50)
  876. {
  877. system("cls");
  878. printf("Signup\n");
  879. printf("Username:");
  880. scanf("%s",username);
  881. i=0;
  882. while((x = username[i]) != '\0')
  883. {
  884. if(x == '|' || x == '#' || x == '$')
  885. {
  886. printf("\n*Username must not contain special characters like |, #, $ etc.");
  887. _getch();
  888. goto main_sec;
  889. }
  890. i++;
  891. }
  892. char accountsDB[100];
  893. fp = fopen("PROJECT_DATA_FILE.txt","r");
  894. i = 0;
  895. while((x = fgetc(fp)) != EOF)
  896. {
  897. accountsDB[i++] = x;
  898. }
  899. fclose(fp);
  900. char temp_pass[100];
  901. if(NULL == strstr(accountsDB, username))
  902. {
  903. i=0;
  904. printf("Password:");
  905. while ((x = _getch()) != '\r')
  906. {
  907. printf("*");
  908. password[i++] = x;
  909. }
  910. password[i] = '\0';
  911. printf("\nRe-Enter password:");
  912. i = 0;
  913. while((x = _getch()) != '\r')
  914. {
  915. printf("*");
  916. temp_pass[i++] = x;
  917. }
  918. temp_pass[i]='\0';
  919. if(strcmp(temp_pass,password)==0)
  920. {
  921. i = 0;
  922. fp = fopen("PROJECT_DATA_FILE.txt","a");
  923. fputc('|',fp);
  924. while((x = username[i]) != '\0')
  925. {
  926. fputc(x,fp);
  927. i++;
  928. }
  929. i = 0;
  930. while((x = password[i]) != '\0')
  931. {
  932. fputc(x,fp);
  933. i++;
  934. }
  935. fputc('$', fp);
  936. fputc('1', fp);
  937. fputc('#', fp);
  938. fputc('1', fp);
  939. fclose(fp);
  940. printf("\n\nSign up successful");
  941. _getch();
  942. goto main_sec;
  943. }
  944. else
  945. {
  946. printf("\n\n*Passwords do not match, try again");
  947. _getch();
  948. goto main_sec;
  949. }
  950. }
  951. else
  952. {
  953. printf("\n*Username is already taken");
  954. _getch();
  955. goto main_sec;
  956. }
  957. }
  958. if(choice==51)
  959. {
  960. system("cls");
  961. printf("Exit\n\n");
  962. printf("Are You Sure Want to Exit\n");
  963. printf("Enter y/n\n");
  964. x=_getch();
  965. if(x=='n'||x=='N')
  966. goto main_sec;
  967. else
  968. {
  969. printf("Thank u for visiting\n");
  970. }
  971. }
  972. }
  973. int char_to_int(char*num)
  974. {
  975. int length=strlen(num);
  976. int var=1;
  977. int i,c=0,temp;
  978. for(i=0; i<length; i++)
  979. {
  980. if(i==0 && num[i]==45 )
  981. {
  982. var=-1;
  983. }
  984. else
  985. {
  986. temp=(num[i]-48);
  987. c=c*10+temp;
  988. }
  989. }
  990. c=c*var;
  991. return c;
  992. }
Add Comment
Please, Sign In to add comment