Help it won't compile!!!!!

This is a discussion on Help it won't compile!!!!! within the C Programming forums, part of the General Programming Boards category; Beautiful programminig style and use of variables but it won't compile 101 error: syntax error before 'printf' I don't use ...

  1. #1
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794

    Talking Help it won't compile!!!!!

    Beautiful programminig style and use of variables but it won't compile
    101 error: syntax error before 'printf'

    I don't use switch statements much or initialise characters arrays much either so maybe the problem is there?
    Probably something simple and stupid but I can't see it.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    FILE *ptr1, *ptr2, *ptr3;
    
    int filelist;
    
    int crds[3][13][13];
    int tots[3];
    char face[13]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
    char typ[3]={'F','M','P'};
    int gg, xx, yy, c1, c2, g1;
    char var2[300]="";
    
    //M 6QUN N        
    
    main(argc,argv)
    	int  argc;
    	char *argv[]; 
    {
     
    	if (	(ptr2=fopen("hands.doc","r")) == NULL) {
    			
    		puts("file2 does not exist");
    		exit(2);	/* an early file does not exist	*/
    	}
    	
    	
    	if (	(ptr3=fopen("handoutput.txt","w")) == NULL) {
    			
    		puts("\nCant open output file");
    		exit(2);	/* an early file does not exist	*/
    	}
    
    	do {  /* for each line in dirfile file */
    		filelist=fscanf(ptr2,"%[^\n]\n",var2);  
    		if (filelist==-1) break;
    
    
    //M 6QUN N        
    		xx=(int)var2[2];
    		yy=(int)var2[3];
    		gg=(int)var2[0];
    
    		switch(xx){
    			case 'A': c1=12; break;
    			case 'K': c1=11; break;
    			case 'Q': c1=10; break;
    			case 'J': c1=9; break;
    			case 'T': c1=8; break;
    			case '9': c1=7; break;
    			case '8': c1=6; break;
    			case '7': c1=5; break;
    			case '6': c1=4; break;
    			case '5': c1=3; break;
    			case '4': c1=2; break;
    			case '3': c1=1; break;
    			case '2': c1=0; break;
    			default: printf("\n Invalid card 1");
    		}
    
    
    		switch(yy){
    
    			case 'A': c2=12; break;
    			case 'K': c2=11; break;
    			case 'Q': c2=10; break;
    			case 'J': c2=9; break;
    			case 'T': c2=8; break;
    			case '9': c2=7; break;
    			case '8': c2=6; break;
    			case '7': c2=5; break;
    			case '6': c2=4; break;
    			case '5': c2=3; break;
    			case '4': c2=2; break;
    			case '3': c2=1; break;
    			case '2': c2=0; break;
    			default: printf("\n Invalid card 2");
    		}
    		switch(gg){
    			case 'P': g1=2; break;
    			case '1': g1=0; break;
    			case '2': g1=0; break;
    			case '5': g1=0; break;
    			case 'C': g1=1; break;
    			case 'M': g1=1; break;
    			default: printf("\n Invalid game type");
    		}
    
    		crds[g1][xx][yy]++;
    		tots[g1]++;
    	}
    
    	printf("\n Done");//<------------------------------------arrrrrrrrgggggggghh!! (line 101)
    
    	for(g1=0;g1<3;g1++){
    
    		if (c1==c2) printf("%c %c%c %d\n", typ[g1], face[c1],face[c2], crds[c1][c2]);
    
    	}
    	fclose(ptr2);
    	fclose(ptr3);
    
    }

  2. #2
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    493
    do needs an while statement.
    main returns an int as per standard.
    global variables are considered to be evil.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by stevesmithx View Post
    do needs an while statement.
    main returns an int as per standard.
    global variables are considered to be evil.
    Spot on!!!!

    It's the 'do' without a while!!!


    Well spotted!!

    The compiler doesn't seem to care about the other stuff
    (and quite frankly neither do I!!! )

    Somewhat more worrying was it complaining about low disk space when I ran it!!
    I had to abort it, dunno whats wrong yet

  4. #4
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    It puts the output (redirected) in to a file I expect I have an infinite loop somewhere.

  5. #5
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Well esbo, with code like this, I can't imagine you'll have too much trouble debugging
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  6. #6
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by NeonBlack View Post
    Well esbo, with code like this, I can't imagine you'll have too much trouble debugging

    <cough> should not take long

    It seems the first line was blank which seemed to 'throw it' somewhat, I have fixed
    that but it does not produce any output apart from a debug line, but at least it has stopped
    filling the hard drive up - that's progress

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Well good luck. I also have to give you credit for this:
    Code:
    		switch(xx){
    			case 'A': c1=12; break;
    			case 'K': c1=11; break;
    			case 'Q': c1=10; break;
    			case 'J': c1=9; break;
    			case 'T': c1=8; break;
    			case '9': c1=7; break;
    			case '8': c1=6; break;
    			case '7': c1=5; break;
    			case '6': c1=4; break;
    			case '5': c1=3; break;
    			case '4': c1=2; break;
    			case '3': c1=1; break;
    			case '2': c1=0; break;
    			default: printf("\n Invalid card 1");
    		}
    		switch(yy){
    			case 'A': c2=12; break;
    			case 'K': c2=11; break;
    			case 'Q': c2=10; break;
    			case 'J': c2=9; break;
    			case 'T': c2=8; break;
    			case '9': c2=7; break;
    			case '8': c2=6; break;
    			case '7': c2=5; break;
    			case '6': c2=4; break;
    			case '5': c2=3; break;
    			case '4': c2=2; break;
    			case '3': c2=1; break;
    			case '2': c2=0; break;
    			default: printf("\n Invalid card 2");
    What's the point in writing functions and reusing the same code when you can just copy-paste code with marginal differences for every global variable?
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > Probably something simple and stupid but I can't see it.
    Buy a mirror then, and the answer will be obvious!
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Okey cokey pig in a pokey!!
    Here is a version which works, what it does is read a file of cards I have been dealt at poker with an input such as:- M K8

    You can ignore the first letter its a 'game type' but the K=KING and 6 = 6

    Then it counts up the number of 'pairs' I have been dealt, there are not many in the test data at the moment.

    Incidently
    M=a game which I used points to enter
    F=a free game (freeroll)
    P=a game I paid money to play - notice I didn't get many pocket pairs!!!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <io.h>
    #include <fcntl.h>
    #include <errno.h>
    FILE *ptr1, *ptr2, *ptr3;
    
    int filelist;
    
    int crds[3][13][13];
    int tots[3];
    char face[13]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
    char typ[3]={'F','M','P'};
    int gg, xx, yy, c1, c2, g1;
    char var2[300]="";
    
    //M 6QUN N        
    
    main(argc,argv)
    	int  argc;
    	char *argv[]; 
    {
     
    	if (	(ptr2=fopen("hands.doc","r")) == NULL) {
    			
    		puts("file2 does not exist");
    		exit(2);	/* an early file does not exist	*/
    	}
    	
    	
    	if (	(ptr3=fopen("handoutput.txt","w")) == NULL) {
    			
    		puts("\nCant open output file");
    		exit(2);	/* an early file does not exist	*/
    	}
    
    	do{  /* for each line in dirfile file */
    		filelist=fscanf(ptr2,"%[^\n]\n",var2);  
    		if (filelist==-1) break;
    //		printf("\n var2<%s>",var2);
    
    
    //M 6QUN N        
    		xx=(char)var2[2];
    		yy=(char)var2[3];
    		gg=(char)var2[0];
    		printf("\n %c %c%c",gg, xx,yy);
    
    		switch(xx){
    			case 'A': c1=12; break;
    			case 'K': c1=11; break;
    			case 'Q': c1=10; break;
    			case 'J': c1=9; break;
    			case 'T': c1=8; break;
    			case '9': c1=7; break;
    			case '8': c1=6; break;
    			case '7': c1=5; break;
    			case '6': c1=4; break;
    			case '5': c1=3; break;
    			case '4': c1=2; break;
    			case '3': c1=1; break;
    			case '2': c1=0; break;
    			default: printf("\n Invalid card 1");
    		}
    
    
    		switch(yy){
    
    			case 'A': c2=12; break;
    			case 'K': c2=11; break;
    			case 'Q': c2=10; break;
    			case 'J': c2=9; break;
    			case 'T': c2=8; break;
    			case '9': c2=7; break;
    			case '8': c2=6; break;
    			case '7': c2=5; break;
    			case '6': c2=4; break;
    			case '5': c2=3; break;
    			case '4': c2=2; break;
    			case '3': c2=1; break;
    			case '2': c2=0; break;
    			default: printf("\n Invalid card 2");
    		}
    		switch(gg){
    			case 'P': g1=2; break;
    			case '1': g1=0; break;
    			case '2': g1=0; break;
    			case '5': g1=0; break;
    			case 'C': g1=1; break;
    			case 'M': g1=1; break;
    			default: printf("\n Invalid game type");
    		}
    
    		(crds[g1][c1][c2])++;
    		(tots[g1])++;
    	} while(1);
    
    	printf("\n Done\n\n");
    //	printf("\n %d"
    	for(g1=0;g1<3;g1++){
    		for(c1=0;c1<13;c1++){
    			for(c2=0;c2<13;c2++){
    					if (c1==c2) printf("%c %c%c %d\n", typ[g1], face[c1],face[c2], crds[g1][c1][c2]);
    			}
    		}
    			printf("\n");
    
    	}
    	fclose(ptr2);
    	fclose(ptr3);
    
    }

    Test output.


    Code:
     M 5Q
     M J9
     M T6
     M 9T
     1 5Q
     1 62
     M 96
     M 87
     M 2J
     M Q2
     M 5Q
     M Q3
     M A5
     M K8
     M TA
     M 62
     M 5K
     M 87
     M T3
     M JA
     M A4
     M 9J
     M J4
     M 2Q
     M 83
     M T3
     M 46
     M 85
     M 74
     M 65
     M 83
     M AJ
     M A9
     M TA
     M 38
     1 JJ
     1 92
     1 23
     1 A9
     M KA
     M J6
     M 84
     1 5A
     1 TT
     M 45
     M KT
     M TA
     M 32
     1 Q2
     1 47
     M A9
     M 48
     M 72
     1 TK
     1 24
     1 QK
     1 A2
     M Q2
     M 98
     M 44
     M 3J
     1 84
     1 45
     1 42
     M 27
     M J9
     M 35
     M 79
     M Q4
     1 4Q
     1 AA
     1 4J
     1 9K
     1 T8
     M K2
     M 98
     M 95
     M 7K
     M 78
     1 A6
     1 JT
     M 38
     M 63
     1 86
     1 82
     1 83
     M K5
     1 JQ
     M JQ
     M T3
     M T5
     M A3
     1 23
     M QA
     M Q6
     1 4J
     M K5
     1 8Q
     1 7J
     M K7
     M 76
     1 3K
     M K4
     1 65
     M 69
     M 85
     M 7Q
     M TQ
     M 4Q
     M 5J
     M TA
     1 QJ
     M T5
     M J3
     1 7T
     1 7T
     M 8K
     1 46
     1 K2
     M TA
     M 23
     M 7J
     M 35
     M 49
     M 78
     1 99
     M 76
     M K5
     1 4T
     1 Q6
     M 6K
     1 K7
     M KJ
     M 6K
     M K4
     M 6T
     M J7
     M 3Q
     M K8
     1 KA
     M A6
     1 37
     M 49
     1 9K
     M 85
     M TQ
     M 52
     M 82
     M 8Q
     M 93
     M 67
     M A9
     M 48
     1 27
     M 7K
     M 53
     1 4A
     1 23
     M 34
     1 Q7
     1 66
     1 46
     M 73
     M 89
     M 79
     M 2A
     M 6K
     M 34
     M K2
     1 87
     1 J8
     M A3
     1 TQ
     M JQ
     M A9
     1 98
     1 6J
     M 7J
     M K7
     1 46
     1 5Q
     1 69
     1 JA
     M 4T
     M 46
     M QA
     1 92
     1 AT
     M 53
     M 3T
     M 7A
     M 97
     M AK
     M T9
     M 5A
     M JJ
     M 64
     M JK
     M 3K
     M J7
     M 28
     M J6
     M 46
     M A4
     1 6J
     1 94
     1 59
     M 37
     M Q2
     1 28
     M K3
     M 62
     M 6A
     1 JT
     1 33
     M 3J
     M 9T
     M 28
     M J8
     M A3
     M 45
     M J9
     M Q9
     M 97
     M 48
     M T5
     M Q6
     M 3K
     M 89
     M 96
     1 Q3
     1 4K
     1 54
     M 2Q
     M 53
     M 93
     M 69
     1 K8
     1 A8
     1 A5
     M Q6
     M 39
     M 37
     M T2
     M J3
     1 54
     1 65
     1 T3
     M 4A
     M 46
     M Q2
     M KQ
     M A6
     M A5
     1 K4
     1 4A
     1 45
     1 A9
     1 4J
     M 2T
     M 9A
     M 2A
     M 32
     M 53
     M 9J
     M J9
     M 8K
     M 69
     1 2Q
     1 5T
     1 68
     1 QQ
     M 7K
     M 5A
     M Q9
     M 37
     M K9
     M 93
     M 7T
     M T3
     M KQ
     M 6J
     M 46
     M 42
     M A7
     M A2
     M QK
     M 3J
     M 65
     M A4
     M 4J
     M 29
     M 8A
     M KA
     M 2J
     M 95
     M 74
     M J6
     M 9A
     M 43
     M K9
     M 52
     M 98
     M QA
     M T9
     M JT
     M 49
     M 4T
     M T2
     M 59
     M 63
     M J8
     M KJ
     M 38
     M A4
     M 73
     M A5
     M QJ
     M 8A
     M T3
     M A5
     M 69
     M 7J
     M 8K
     M 5A
     M KA
     M 9A
     M 2K
     M 5K
     M 8K
     M 89
     M 9Q
     M 53
     M 73
     M 47
     M 6T
     M K7
     M 54
     M 99
     P 87
     P Q7
     P KT
     P 76
     P 62
     P 37
     P T4
     P 8J
     P 7Q
     P 28
     P JK
     P 95
     P 8T
     P AQ
     P 5Q
     P 24
     P 4J
     P KT
     P JK
     P A8
     P 62
     P 99
     P 3A
     P 56
     P 98
     P JQ
     P JQ
     P 93
     P J9
     P 46
     P A5
     P J8
     P 7T
     P 29
     P Q9
     P 4J
     P TJ
     P 3Q
     P 9A
     P 32
     P 3Q
     P 67
     P Q5
     P 44
     P Q2
     P 2K
     P K3
     P 5T
     P TJ
     P 72
     P 5A
     P J2
     P Q6
     P 8T
     P 9A
     P JT
     P 5J
     P Q9
     P 2K
     P J6
     P A7
     P 3K
     P KQ
     P 69
     P 79
     P 98
     P A6
     P Q4
     P 95
     P JT
     Done
    
    F 22 0
    F 33 1
    F 44 0
    F 55 0
    F 66 1
    F 77 0
    F 88 0
    F 99 1
    F TT 1
    F JJ 1
    F QQ 1
    F KK 0
    F AA 1
    
    M 22 0
    M 33 0
    M 44 1
    M 55 0
    M 66 0
    M 77 0
    M 88 0
    M 99 1
    M TT 0
    M JJ 1
    M QQ 0
    M KK 0
    M AA 0
    
    P 22 0
    P 33 0
    P 44 1
    P 55 0
    P 66 0
    P 77 0
    P 88 0
    P 99 1
    P TT 0
    P JJ 0
    P QQ 0
    P KK 0
    P AA 0
    Gonna run a huge test now and count all card hands, not just 'pocket pairs'. in the paid game!!
    and see it the distribution is even

    Actually I just realised I didn't play many paid games!! (so thats OK), I wil have to average it.
    Last edited by esbo; 01-02-2009 at 12:15 AM.

  10. #10
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    OK here is a run with a load of data fairly even but notice I get a much higher proportion
    of AA (pocket aces) in the free games!!

    Code:
    
     Done
    
    F 22 105
    F 33 93
    F 44 90
    F 55 76
    F 66 96
    F 77 84
    F 88 90
    F 99 93
    F TT 105
    F JJ 91
    F QQ 99
    F KK 97
    F AA 106
    
    M 22 114
    M 33 80
    M 44 86
    M 55 80
    M 66 85
    M 77 81
    M 88 89
    M 99 90
    M TT 80
    M JJ 93
    M QQ 81
    M KK 72
    M AA 104
    
    P 22 212
    P 33 206
    P 44 236
    P 55 204
    P 66 225
    P 77 231
    P 88 194
    P 99 201
    P TT 230
    P JJ 206
    P QQ 198
    P KK 205
    P AA 226

  11. #11
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    OK here is a run on 87 thousand hands!!!
    The number at the end is the average number of hands it takes to be dealt that pair the normal value is 1 in 221 (13 X 17). So anything lower than 221 is good.

    I will work out how often I hit a 'set' (3 of a kind) next.

    Code:
    
     Done
    
    F 22 105   205.1 
    F 33 93    231.5 
    F 44 90    239.2 
    F 55 76    283.3 
    F 66 96    224.3 
    F 77 84    256.3 
    F 88 90    239.2 
    F 99 93    231.5 
    F TT 105   205.1 
    F JJ 91    236.6 
    F QQ 99    217.5 
    F KK 97    222.0 
    F AA 106   203.1 
    
    M 22 114   165.8 
    M 33 80    236.3 
    M 44 86    219.8 
    M 55 80    236.3 
    M 66 85    222.4 
    M 77 81    233.3 
    M 88 89    212.4 
    M 99 90    210.0 
    M TT 80    236.3 
    M JJ 93    203.2 
    M QQ 81    233.3 
    M KK 72    262.5 
    M AA 104   181.7 
    
    P 22 212   220.9 
    P 33 206   227.3 
    P 44 236   198.4 
    P 55 204   229.5 
    P 66 225   208.1 
    P 77 231   202.7 
    P 88 194   241.4 
    P 99 201   233.0 
    P TT 230   203.6 
    P JJ 206   227.3 
    P QQ 198   236.5 
    P KK 205   228.4 
    P AA 226   207.2

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > Okey cokey pig in a pokey!!
    Exactly, you can put as much lipstick as you like on your programs, but they're still pigs.

    There is little point in helping you to fix it; the mould was set a long time ago and can no longer be broken.

    You wouldn't learn anything this time, that hasn't already been explained over and over to you on many previous problems.

    > Beautiful programminig style and use of variables
    The only one buying your inflated PR image of yourself is you.
    You might think you're an ocean, but to me you look like a car-park puddle.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Salem View Post
    > Okey cokey pig in a pokey!!
    Exactly, you can put as much lipstick as you like on your programs, but they're still pigs.

    There is little point in helping you to fix it; the mould was set a long time ago and can no longer be broken.

    You wouldn't learn anything this time, that hasn't already been explained over and over to you on many previous problems.

    > Beautiful programminig style and use of variables
    The only one buying your inflated PR image of yourself is you.
    You might think you're an ocean, but to me you look like a car-park puddle.

    Whatever I don't need to learn anything from you because my programme works fine, and the thing I had a problem with was nothing to do with programming style or global variables. So get off your high horse, it's a donkey in reality.


    I don't normally use 'do while' loops, I would normally have broken out of a 'while' loop but I copied it from a program I did ages ago.
    Last edited by esbo; 01-02-2009 at 11:14 AM.

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Quote Originally Posted by esbo View Post
    So get off your high horse, it's a donkey in reality.
    You need to get off your high horse and realize why they are called good programming practices. Until you do, you have no right to tell anyone else to step down from their high horse.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    You need to get off your high horse and realize why they are called good programming practices. Until you do, you have no right to tell anyone else to step down from their high horse.
    What is good programming practise is what works for me.

    You can write your programs how you like I and I will do the same.

    I don't have time to waste following unproven rules.

    I have no time for programming dogma.

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 01:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 12:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 07:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 08:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 01:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21