Thread: Can someone help me with a school project

  1. #1
    Registered User
    Join Date
    Jan 2016

    Question Can someone help me with a school project

    Hey all,

    I'm new here and came here to ask you a question about my school exercise but can't find out what the problem is...

    I need to scan in one file where numbers are fully written in 20 sentences and I need to print them in the good order in another file. from high to low starting at 20

    I've set up a long else if statement from 0 to 20 (in Dutch) but I can't get any further. I was thinking to get them into a 2D array so 20 gets on out[0], 19 on out[1], etc.

    Now that's a problem that isn't going that well.
    After that I just need to fprintf it in the file.

    Can someone help me?

    The source code I have now:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main (int argc, char *argv[]) {
        char regel [255];
        char out [25][255];
        FILE *myFile;
        FILE *myFile1;
        myFile = fopen (argv[1], "r");      //in
        if (myFile == NULL) {         // foutmelding
            printf ("leesfout\n");
            return -1;
        myFile1 = fopen (argv[2], "r");     //out
        if (myFile1 == NULL) {         // foutmelding
            printf ("leesfout\n");
            return -1;
        while (fgets (regel, 255, myFile) != NULL)  {
            if(regel[0]=='t' && regel[3]=='a') {        //twintig
            }else if(regel[0]=='n' && regel[7]=='e'){   //negentien
            }else if(regel[0]=='a' && regel[5]=='e'){   //achtien
            }else if(regel[0]=='z' && regel[5]=='t'){   //zeventien
            }else if(regel[0]=='z' && regel[3]=='t'){   //zestien
            }else if(regel[0]=='v' && regel[2]=='j' && regel[6]=='e'){   //vijftien
            }else if(regel[0]=='v' && regel[2]=='e' && regel[6]=='e'){   //veertien
            }else if(regel[0]=='d' && regel[2]=='r'){   //dertien
            }else if(regel[0]=='e' && regel[1]=='l'){   //elf
            }else if(regel[0]=='t' && regel[1]=='i'){   //tien
            }else if(regel[0]=='n' && regel[4]=='n' && regel[5]!='t'){   //negen
            }else if(regel[0]=='a' && regel[1]=='c' && regel[4]!='t'){   //acht
            }else if(regel[0]=='z' && regel[4]=='n' && regel[5]!='t'){   //zeven
            }else if(regel[0]=='z' && regel[2]=='s' && regel[5]!='t'){   //zes
            }else if(regel[0]=='v' && regel[3]=='f' && regel[5]!='t'){   //vijf
            }else if(regel[0]=='v' && regel[2]=='e'){                    //vier
            }else if(regel[0]=='d' && regel[1]=='r'){                    //drie
            }else if(regel[0]=='t' && regel[2]=='e'){                    //twee
            }else if(regel[0]=='e' && regel[1]=='e'){                    //een
        printf("%s", out[0]);
        fclose (myFile);
        fclose (myFile1);
        return 0;
    Thank you!

    EDIT : I'm dutch, so all the full written words are Dutch.

    Also, Twelve is missing, it's called twaalf in Dutch, in some kind of way that didn't work...
    Last edited by lexprdn; 01-31-2016 at 03:13 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > myFile1 = fopen (argv[2], "r");
    You should use "w" mode if you want to write to a file.

    > if(regel[0]=='t' && regel[3]=='a')
    Unless you can guarantee a minimum matching subset in all cases, you're probably going to find it easier if you begin with say
    if ( strncmp(regel,"twintig",7) == 0 )

    Perhaps a table of words, and a for loop, rather than an endless series of if / else if
    char *words[] = {
    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.

  3. #3
    Registered User
    Join Date
    Jan 2016
    I can't just put that table in to print that into the file, my teacher will check that...
    I need to get it from a scanned file... so when there is a sentence missing that number won't be printed.

    but thanks for that w at myFile1

    the only problem is to get them in the right order...

    Or didn't you mean it like that?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my school project!!!
    By Maciek Grodzki in forum C Programming
    Replies: 5
    Last Post: 01-07-2014, 07:53 AM
  2. School Project Help
    By Joshua Hess in forum C++ Programming
    Replies: 9
    Last Post: 02-19-2013, 07:27 PM
  3. School project help
    By blckgoat in forum C Programming
    Replies: 8
    Last Post: 11-14-2011, 06:03 PM
  4. school project help
    By yogai in forum C Programming
    Replies: 8
    Last Post: 09-09-2004, 06:03 PM
  5. Help with School Project
    By jtouron in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2003, 12:27 AM

Tags for this Thread