How do you get a 15x15 matrix using an ifstream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lolcheelol
    New Member
    • Feb 2010
    • 25

    How do you get a 15x15 matrix using an ifstream

    Code:
    ifstream in1("txtxtxtx");
    int ct=0;
    int *p=new int[1300];
    int forever=1;
    
    while(forever){ 
    in1 >> *(p+ct); 
    
    if(*(p+ct) == -1) break;
    ct++; 
    } // WHILE LOOP
    
    for(int i=0; i<ct; i++){
    cout << "\t" << *(p+i);
    if((ct)%15==0) cout << "\n";
    if((ct)%150==0) cout << "Enter to continue";
    } // FOR LOOP
    getch();
    
    cout << "\n\n\tTotal data = " << ct;
    delete p; 
    in1.close();
    So basically I'm trying to get a 15x15 matrix of the numbers from the text file I have and after a 15x15 matrix is printed I want the user to have the option to hit a key to continue. It prints all the numbers correctly, but it doesn't do the matrix in the way I would like it to. Any help is appreciated. Thanks
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    What are you getting and what do you want?

    Comment

    • lolcheelol
      New Member
      • Feb 2010
      • 25

      #3
      this is what i'm getting.

      6 198 651 694 692 196 594 762 698
      321 265 517 559 1010 648 131 621 968 513
      544 30 863 827 688 311 758 284 729 845
      285 164 896 343 1009 23 371 429 516 316
      357 470 1007 789 181 530 56 148 214 726
      1016 871 398 766 423 728 657 606 496 249
      119 942 410 937 362 592 755 159 251 563
      678 938 683 201 877 204 121 120 192 380
      40 261 773 645 586 904 482 2 17 63
      194 509 221 387 433 579 359 356 510 403
      348 526 390 786 86 512 714 82 260 206
      302 701 150 888 59 700 329 803 596 788
      100 314 219 166 354 113 253 68 436 614
      1012 1021 911 612 853 39 640 385 331 894
      949 432 522 624 459 984 342 553 187 446
      965 663 816 619 126 293 1022 545 748 27
      824 564 5 836 442 636 197 608 826 450
      381 957 671 70 236 550 146 763 55 310
      572 488 93 313 575 1008 801 525 715 774
      402 865 905 94 97 552 435 697 1018 13
      882 931 494 838 244 118 807 231 941 224
      860 295 186 777 397 389 754 338 898 946
      468 1014 780 537 932 752 176 528 964 542
      660 915 643 555 157 347 438 1020 388 878
      950 444 62 337 585 987 315 641 976 422
      373 527 178 966 587 969 64 274 607 851
      639 303 693 498 476 167 569 106 395 649
      995 379 50 369 102 1015 46 628 77 797
      300 73 735 901 271 1002 42 577 222 142
      740 140 887 676 275 702 890 521 779 713
      180 202 200 506 91 561 484 372 885 143
      99 237 848 243 234 821 971 103 574 116
      15 35 912 308 744 925 908 289 1001 11
      280 804 246 535 365 419 229 813 599 168
      57 732 160 210 367 138 427 21 708 511
      88 7 778 12 363 672 751 980 502 914
      239 709 109 223 874 462 749 480 493 903
      881 247 4 453 539 294 266 264 696 985
      474 979 26 704 917 864 560 111 920 515
      681 205 370 1 632 208 523 52 286 74
      424 364 95 376 296 24 259 798 426 254
      114 318 155 309 16 721 434 795 664 1011
      320 125 549 207 658 165 615 742 605 741
      98 341 487 669 399 8 642 829 25 616
      72 83 986 943 916 217 129 185 880 899
      855 844 182 108 475 440 378 602 305 133
      737 782 799 654 595 298 769 787 584 923
      334 1013 746 805 566 981 49 934 122 404
      144 130 33 22 336 791 69 486 582 472
      520 988 518 54 854 171 327 252 14 139
      48 897 652 924 483 831 810 936 1019 747
      921 497 392 682 837 479 292 820 884 112
      828 333 907 28 944 618 918 765 951 790
      601 361 469 647 213 546 720 919 190 152
      665 567 282 514 989 134 411 416 841 428
      731 461 75 1017 834 597 227 733 947 452
      705 115 85 29 291 464 89 686 250 258
      707 653 879 591 818 324 859 255 455 161
      993 588 893 346 961 307 785 536 158 580
      431 335 650 58 783 623 626 456 929 220
      963 147 71 939 730 211 193 945 374 633
      781 127 360 832 36 617 394 290 232 830
      172 935 933 767 400 952 3 233 967 350
      383 909 449 241 892 858 990 970 711 998
      508 154 562 465 1023 533 630 784 634 124
      802 188 323 598 978 955 495 739 876 718
      216 297 84 273 151 557 866 576 646 954
      629 611 352 842 991 812 445 344 529 558
      80 554 953 287 110 104 870 822 136 270
      891 413 420 466 603 583 10 240 668 719
      556 299 662 622 96 568 926 76 677 900
      775 170 699 792 930 330 600 107 958 776
      609 153 927 761 972 268 256 638 301 983
      750 997 538 541 540 137 604 531 817 500
      430 174 690 61 1004 764 928 396 199 409
      358 867 856 982 345 504 281 910 269 458
      756 226 519 312 471 375 551 875 355 325
      20 45 60 814 209 806 212 1006 625 457
      895 637 117 203 183 532 328 283 53 712
      886 145 245 490 391 873 716 43 685 218
      163 175 667 906 9 548 366 81 809 996
      815 589 679 571 66 179 823 332 745 973
      418 695 492 808 230 415 412 962 760 79
      437 191 691 278 408 794 710 590 242 478
      340 101 248 578 825 570 959 796 377 18
      833 132 135 38 195 680 386 852 263 507
      78 34 351 627 768 977 659 304 505 999
      674 835 501 173 473 547 51 177 736 703
      65 257 414 491 565 353 843 184 734 793
      87 725 811 368 994 872 401 913 489 32
      235 1003 723 317 421 384 759 481 635 19
      753 339 534 326 1005 922 31 675 770 847
      406 156 463 277 960 800 189 306 123 477
      447 37 485 684 322 439 460 724 41 902
      228 738 454 349 656 620 743 940 105 581
      655 267 869 631 593 149 771 276 543 441
      407 262 1000 67 689 524 757 839 846 128
      727 868 706 850 288 44 974 883 666 47
      673 272 503 956 670 613 889 393 425 90
      141 238 717 948 722 975 644 162 772 405
      451 448 992 862 840 573 215 499 92 279
      610 857 849 169 661 382 687 819 225 417

      Total data = 1019
      Complete

      sorry for the large amount of text, but i wanted to be thorough.

      i want this(obviously not the same numbers, but just making it easier for myself to show you)


      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
      6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648

      Enter to continue...

      then it just repeats. till the numbers finish outputting from the text file.

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        The loop variable is i, but you always check for ct % something, that is constant throughout the loop.

        Comment

        • lolcheelol
          New Member
          • Feb 2010
          • 25

          #5
          that doesn't make alot of sense to me because my count is telling me how many numbers i have...

          Comment

          • newb16
            Contributor
            • Jul 2008
            • 687

            #6
            So why do you want to print next line after each number if total number of items divides by 15?

            Comment

            • lolcheelol
              New Member
              • Feb 2010
              • 25

              #7
              so it looks like this in the output

              6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
              6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648

              Enter to continue...

              not

              6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
              6 198 651 694 692 196 594 762 698 321 265 517 559 1010 648
              Enter to continue...

              does my question make sense? i know my actual coding is right because i'm getting the numbers, i just would like to know why the matrix isn't working

              Comment

              • newb16
                Contributor
                • Jul 2008
                • 687

                #8
                It's because _that_ part of coding that is responsible for making matrix _isn't_ right.

                Comment

                • lolcheelol
                  New Member
                  • Feb 2010
                  • 25

                  #9
                  so your saying it should be i instead of ct? i'm not really getting what your saying.

                  Comment

                  Working...