Thread: Can't solve my syntax error...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9

    Unhappy Can't solve my syntax error...

    I need help in figuring out a syntax error I have in my code. I've been playing around with it and still have not figured out exactly how to fix the syntax error.

    Code:
    #include "stdafx.h"
    #include "stdio.h"
    /*Objective: To implement a simple drawing program. The program will
    draw on the screen a series of figure(boxes). It will repeatedly ask
    the user to enter the loaction and dimensions.*/
    
    int main()
    {
    char mat[20][40];
    int col, row, x, y, width, height;
    int stop=0;
    int letter=3;
    
    for(row=0;row<20;row++)
    {
    for(col=0;col<40;col++)
    {
    mat[row][col]='.';
    }
    }
    do
    {
    printf("Enter x0, y0, width, height:");
    if(scanf("%i%i%i%i",&x,&y,&width,&height)==EOF)
    {
    	stop=1;
    }
    else
    {
    	printf("  0000000000111111111122222222223333333333\n");
    	printf("  0123456789012345678901234567890123456789");
    	for(row=0;row<20;row++)
    	{
    		if (row<10)
    		{
    			printf("0%d", row);
    			printf("\n");
    		}
    			else
    			{
    				printf("%d", row);
    				printf("\n");
    			}
    	for(col=0;col<40;col++)
    	{
    	if((col==x)||(col==(x+width-1))||((row==y)||(row==(y+height-1))))
    	{
    	if((col>=x)&&(col<=(x+width-1))&&((row>=y)&&(row<=(y+height-1))))
    	{
    		mat[row][col]=letter;
    		printf("%c",mat[row][col]);
    	}
    	if(col==39)
    	{
    	printf("\n");
    	}
    	}
    	}
    }
    }
    letter++;
    }
    while(!stop);
    for(;;);
    return 0;
    }

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    First of all, you should clearly post the error you're receiving. Most of us are lazy, jaded ........s who won't bother to compile your code to see for ourselves.

    Anyhow - "#include <stdio.h>", using < and > not double quotes.

    Think it's the same thing with stdafx.h - Isn't that some visual studio file?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And I guess you want US to figure out where it is by compiling your code on our machines, and then tell you how to fix it? How about posting the compiler error.

    [And by the way, in my compiler, it doesn't produce any errors at all - but that could be because I don't have the same "stdafx.h" as you use for example]. It does produce warnings about a type conversion (correctly as you are using an int to stuff into a char array) and about unreachable code (you have a "for(;;" before the return 0; at the end of main - obviously, the compiler can't figure out why you bother with a return if you're never going to get there anyways - but it would probably complain about no return statement if you remove it.)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by IceDane View Post
    First of all, you should clearly post the error you're receiving. Most of us are lazy, jaded ........s who won't bother to compile your code to see for ourselves.

    Anyhow - "#include <stdio.h>", using < and > not double quotes.

    Think it's the same thing with stdafx.h - Isn't that some visual studio file?
    Actually, stdafx.h is a "project" file, so it should probably not have <>. And it really makes little difference which you use unless there are multiple files with the same name, some of which are in the "current directory" and some of which are in the "compiler / system directories". In all other cases, the compiler will find the right one wherever it is [although sometimes the compiler will need some convincing to fine <> files in the current directory].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9
    I believe that my syntax error has to do with "letter" and I am programming on a Windows OS.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, post the exact error message, including which line of code it relates to "I believe it's to do with letter" isn't really helpfull [ok, so there's only a few lines that involve letter - but what if it wasn't really letter because you believe wrong, or some such?]

    Playing "twenty questions" isn't quite as fun when you are doing it to try to offer help as it is when you are doing it as a challenge as a way to enjoy yourself on a boring trip or in the pub when there's not much else to do. Ok?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by matsp View Post
    Actually, stdafx.h is a "project" file, so it should probably not have <>. And it really makes little difference which you use unless there are multiple files with the same name, some of which are in the "current directory" and some of which are in the "compiler / system directories". In all other cases, the compiler will find the right one wherever it is [although sometimes the compiler will need some convincing to fine <> files in the current directory].

    --
    Mats
    AFAIK, gcc searches for include files enclosed in quotes in the current directory but include files enclosed in < > in the proper include directories.

    I might be wrong though.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, by default gcc doesn't search the current directory for <> enclosed files. If you use " " then it searches in current directory FIRST, then in the path. So it will work perfectly fine (although slightly confusing) to use "stdio.h" - but not <myheader.h> because it doesn't find it in the common directories.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    Omaha, Nebraska
    Posts
    116
    ok, once i commented out the stdafx.h file, it compiled just fine for me with gcc.
    printed some kinda goofy results, but i assume that it has to do with the custom header file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM