Thread: Ascii charecter to integer

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    55

    Ascii charecter to integer

    I have a bowling program that runs right now with numbers. I want to change spares and strikes to /s and Xs. How would you go about handling this problem? Where should I start?

    Below is the bowling program...
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    
    {
    
    FILE *ifp;
    
    int N, x;
    char fname[21];
    
    printf("Enter the filename: ");
    
    scanf("%s", fname);
    
    //Open
    
    ifp = fopen(fname, "r");
    
    //If no file
    
    if (ifp == NULL)
    
    {
    
      printf("Error, %s not available\n", fname);
    
      exit(1);
    }
    
     
       int scores[22];
       int i, y;   
    
    //Array storage
    
       for(i = 0; i<22; ++i)
       {
         fscanf( ifp, "%d", &y);
         if(y == -1)
         {
         scores[i] = y;
         break;
         }
         scores[i] = y;
       }
    int howmany;
    howmany = i;
    
    //Prints SUM
    
    i = 0;
    int c=0;
    while(scores[i] != -1)
       {
       c = scores[i] + c;
       ++i;
       }
       
    printf("SUM: %d\n\n",c);
    printf("N = %d\n", howmany);
    printf("----------------------\n");
    
    
    
    int f,e,total;
    
    y = 0;
    e = 0;
    total = 0;
    
    //Scores total with strike, spare rules
    
    for (y=0;y<22;y++)
       {
    
    if(scores[e] == 10)
       {
       total = total + 10 + scores[e+1] + scores[e+2];
       printf("Frame %2d: Total %2d\n",y+1, total);
       e = e + 1;
       printf("STRIKE!\n");
       }
    else if(scores[e] + scores[e+1] == 10)
       {
       total = total + 10 + scores[e+2];
       printf("Frame %2d: Total %2d\n",y+1, total);
       e = e + 2;
       printf("SPARE!\n");
       }
    else if(scores[e] == -1)
       { 
       printf("----------------------\n");
       printf("Your final score is: %2d", total);
       break;
       }
    else
       {
       total = total + scores[e] + scores[e+1];
       printf("Frame %2d: Total %2d\n",y+1, total);
       e = e + 2;
       }
       }
    
    return 0;
    
    }
    And here is the file the program reads from...

    Code:
    10 10 10 1 0 1 9 2 2 1 6 3 2 10 1 2  -1

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Why not make the output of your program, look just like a score sheet in bowling?

    In fact, if I were going to do it, I'd get a score sheet to make sure my output was just what every bowler expects to see (within the limitations of a console terminal).


    You can print all kinds of char's if you take a look at the character set your operating system and BIOS is using. Downloading an ascii table might be a good place to start, but surely you know how to print up a horizontal and vertical line, an X and a /, already.

    You will probably want to use SetConsoleCursorPosition() if you're on Windows, unless you have conio.h support in your compiler.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 08:38 PM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM