Thread: matrix+file

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    3

    matrix+file

    The BTR Bank began using a new scanner to process the checks used. The scanner converts the horizontal and vertical lines of the numbers into ASCII symbols '|' (ASCII code 124) and '_' (code 95).
    Thus, after scanning, a sequence of vertical, horizontal lines and spaces is formed. It is known that each check has a number of 9 digits and for each number the condition is fulfilled: (d1 + 2*D2 + ... + 9*D9) mode 11 = 0, where di is a number of the number. Numbers are numbered from right to left: d9d8d7d6d5d4d3d2d1.
    There are errors in the scanning process.
    Write a program that determines the correct number of the check if it is known that:
    • If the read number is admissible for the check, then it is correct;
    • Erroneously read no more than one digit;
    • No additional lines appear on scanning.
    input
    The input file contains the scanned image of height 3 and length of 27 symbols. Each figure occupies a 3 × 3 square.
    output
    The file contains either the correct number of the check or the failure message, if the number can not be restored, or the ambiguous message if there are several solutions.

    _ _ _ _ _ _ _
    | _ | _ || _ || _ | _ || _ || _ |
    || _ _ | | | _ || _ | || _ | _ |

    Example output
    123456789
    Last edited by Salem; 10-07-2018 at 12:51 PM.

  2. #2
    Registered User
    Join Date
    Oct 2018
    Posts
    3
    can somebody help me, please

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Help you with what? You haven't asked any questions, all you have done is post the assignment. You need to post the code that you've written and then ask specific questions about that code.

    Also you need to post a small sample of your input file, within code tags to preserve spacing.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So what are you stuck on?

    Reading a single line from a file?
    Reading three lines from a file?
    Extracting 3x3 cells from three lines?

    Show some effort to the point where you're stuck, then we'll help.

    This isn't a homework on demand service where you can dump your assignment and get a ready made answer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2018
    Posts
    3
    insert
    Code:
    #include<stdio.h>
    
    
    
    int main(){
        FILE *f,*f1;
        int i, j;
        f = fopen("‪problema29.txt", "r");
        if (f==NULL) perror("error opening file");
        else{}
        char a[3][27];
                
         f1=fopen("output.txt","w");
        for (i = 0; i < 3; i++)
            for(j = 0;j<27;j++) { fscanf(f, "%c", &a[i][j]);
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]==' ' && a[i+1][j+2]=='|' && a[i+2][j]=='|' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'0') //printf("0");
             if (a[i][j]==' ' && a[i][j+1]==' ' && a[i][j+2]==' ' && a[i+1][j]==' ' && a[i+1][j+1]=='|' && a[i+1][j+2]==' ' && a[i+2][j]==' ' && a[i+2][j+1]=='|' && a[i+2][j+2]==' ')  fprintf(f1,"%c",'1')  //printf("1");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]=='|' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]==' ' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]==' ')  fprintf(f1,"%c",'2') //printf("2");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]==' ' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'3')  //printf("3");
             if (a[i][j]==' ' && a[i][j+1]==' ' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]==' ' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'4')  //printf("4");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]==' ' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'5') //printf("5");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]==' ' && a[i+2][j]=='|' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'6') //printf("6");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]==' ' && a[i+1][j+1]==' ' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]==' ' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'7') //printf("7");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]=='|' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'8') //printf("8");
             if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|')  fprintf(f1,"%c",'9')//printf("9");
        fclose(f);}
        fclose(f1);
        }
        f1=fopen("output.txt","r+");
        int s;
        char v[9];
        fscanf(f1,"%c",&v[s]);
            if((v[i]+2*v[i+1]+3*v[i+2]+4*v[i+3]+5*v[i+4]+6*v[i+5]+7*v[i+6]+8*v[i+7]+9*v[i+8])%11==0){
                fprintf(f1,"%c%c%c%c%c%c%c%c%c",v[i+8],v[i+7],v[i+6],v[i+5],v[i+4],v[i+3],v[i+2],v[i+1],v[i]);} else fprintf(f1,"failure");
    
    
         }
    this is not an exam, just a problem from my homework!
    what is the next i need to do? if you want help me
    Last edited by alex0101; 10-12-2018 at 01:23 AM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The first thing is to comment out lines 16 to 25.
    You can't begin to analyse the data until you've finished reading in all the data.

    You also need to be aware that %c will read and store newlines along with your regular data, so you need to account for this as well.

    Your first step should be
    - read in a 3x27 matrix
    - print a 3x27 matrix

    Make sure your data has been read in correctly before trying to analyse it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with matrix reading from a file
    By kimblie in forum C Programming
    Replies: 4
    Last Post: 08-30-2016, 02:00 PM
  2. Replies: 2
    Last Post: 05-19-2014, 07:32 PM
  3. Reading txt file to a MATRIX
    By Cosmo S in forum C Programming
    Replies: 2
    Last Post: 01-11-2013, 04:40 AM
  4. Matrix in a file. Help!
    By Arminel in forum C Programming
    Replies: 6
    Last Post: 12-25-2006, 07:18 PM
  5. transposing matrix from file to file
    By inky in forum C Programming
    Replies: 4
    Last Post: 07-19-2005, 08:25 PM

Tags for this Thread