Thread: 2-d array

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    4

    2-d array

    I have a small glitch in my prog I am using qunicy99 and file redirection of following text...my purpose is to scan their pins and marks down score and know the winner....

    But i am stuck at the scanning and displaying the pin... ur help with be appreciated if u could just figure out the glitch why it is running twice for each players

    Code:
    #include<stdio.h>
    #include<string.h>
    int
    main(void)
    {
    	char players[200];
    	int i,j,k,l;
    	int frames[10][2];
    	int frame11,frame12,trash;
    	while (strcmp (gets (players) ,"End of data") != 0) {
    			printf("\n\n\n\n                Frame  1    2    3    4    5    6    7    8    9    10 \n\n");
    			puts(players);
    			printf("                     ");
    			for(j=0;j<=8; j++) {
    					k=0;
    					scanf("%d",&frames[j][k]);
    					if(frames[j][k]<10) {
    							scanf("%d",&frames[j][k+1]);
    							printf(" %d-%d ",frames[j][k],frames[j][k+1]);
    						} else if(frames[j][k] ==10) {
    							frames[j][k+1] =0;
    							printf("  X  ");
    						}
    					if(j==8) {
    							k=0;
    							j=j+1;
    							scanf("%d",&frames[j][k]);
    							if (frames[j][k] ==10){
    									scanf("%d", &frame11);
    									scanf("%d", &frame12);
    									scanf("%d", &trash);
    									printf(" X/%d/%d",frame11,frame12);
    								}
    							else if(frames[j][k] !=10){
    								scanf("%d",&frames[j][k+1]);
    							l = frames[j][k]+frames[j][k+1];
    							if(l == 10){
    									scanf("%d", &frame11);
    									printf(" %d/%d",frames[j][k],frame11);
    									scanf("%d", &trash);}
    							else if (l !=10){
    									printf(" %d-%d",frames[j][k],frames[j][k+1]);
    									scanf("%d", &trash);}
       						}}
    
    				}
    		}
    	return(0);
    }
    Last edited by unique135; 12-03-2005 at 10:32 AM.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well to put it simply, your not getting output because your while doesn't evaluate true. Secondly, why do you have a text file? There is no file I/O in that program.
    Last edited by SlyMaelstrom; 12-03-2005 at 10:38 AM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    4
    I have having output for where it give me their pin down in each frames and output for final evaluation i have not entered in it but for some reason there is double output of pin down for each players. I dont get that why.


    I have to use text for i am getting my players name and number data from text file.


    Code:
    MY RESULTS
    
    
                    Frame  1    2    3    4    5    6    7    8    9    10
    
    Fred Flintstone
                           X    X   6-4   X   8-2  9-1  4-5  3-6  5-3  X/7/2
    
    
    
                    Frame  1    2    3    4    5    6    7    8    9    10
    
    
                           X    X   6-4   X   8-2  9-1  4-5  3-6  5-3  X/7/2
    
    
    
                    Frame  1    2    3    4    5    6    7    8    9    10
    
    Barney Rubble
                          7-3   X    X    X   2-8  1-9  5-4   X   2-3  7/4
    
    
    
                    Frame  1    2    3    4    5    6    7    8    9    10
    
    
                          7-3   X    X    X   2-8  1-9  5-4   X   2-3  7/4
    
    
    
                    Frame  1    2    3    4    5    6    7    8    9    10
    
    Joe Rockhead
                          8-0  7-0  9-0   X   8-1  9-1  7-1  6-1  4-1  9/7
    
    
    
                    Frame  1    2    3    4    5    6    7    8    9    10
    
    
                          8-0  7-0  9-0   X   8-1  9-1  7-1  6-1  4-1  9/7
    Any key to return to Quincy...

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Don't use gets(). It's dangerous.

    I'm going to guess that you need to flush the input buffer (not with fflush(stdin), though). See the FAQ.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Why do they have these students read text files? Nothing is stored in text format.

    Do your own homework bud and stop cramming the boards with your bowling crap. Your antics are not working here or on any other board.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    4
    why do u get lost do some ........ty program

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    4
    Anyways for other helping out thanx a lot

    I finally got it working...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM