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:
Code:
#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
}else{
}
}
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...