C program that displays shapes. Keep getting errors.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The age old *nix phrase RTFM comes to mind . If you really spent that long at troubleshooting it then here's some tips so you don't commit suicide (waiver, I'm not implying you should commit suicide ).
#1
Find a spot on the wall that is far away. Every 10 minutes or so take your eyes away from the screen and look at that far away spot. Look at it until at least your eyes sharply focus on the object or picture you picked. Otherwise your eyesight will start to fade.
#2
Sometimes enough is enough. You have to force yourself to put the code down. I've troubleshooted code for over 4 hours before and then said heck with it. I can't find it right now. I left it for a couple days or at least a day. Then when I came back I found the error within seconds and continued on code. It really does help to move away from it and come back later so you're not wasting 16 of your 20 hours.
Other than that the only thing we, as in LQ members, can do is to help you here and give you hints there; refer you to reference material; etc. It is a habit of mine and others to not just give you the answer. We give you where the answers can be found so that the user may better themselves by reading it, thus becoming a better programmer, and becoming a better human being by reinforcing troubleshooting skills by causing them to think.
I say that because Sergei Steshenko is not f**king with you. He's trying to show you where you can find the answer so you can better yourself. Telling you the answer in cases like this almost never helps. Another thing you should consider is time. Members at LQ donate their time and it is not always prudent for us to read the documentation for you and then give you the verbatim answer. So we show you where it can be found.
I just wanted to explain that before you exploded into a rage because I can see you're frustrated and we're doing our best to guide you.
At this point I'm just trying to get the program to compile.
These are the errors.
The ones I don't understand are the "expected expression before" and "expected identifier" ones.
shape2.c: In function âmainâ:
shape2.c:16: error: expected expression before â)â token
shape2.c:18: error: âshapeâ undeclared (first use in this function)
shape2.c:18: error: (Each undeclared identifier is reported only once
shape2.c:18: error: for each function it appears in.)
shape2.c:29: error: expected â,â or â;â before â)â token
shape2.c:51: error: expected expression before âforâ
shape2.c:70: error: expected expression before âbreakâ
shape2.c:71: error: expected expression before â}â token
shape2.c: At top level:
shape2.c:72: error: expected identifier or â(â before â}â token
shape2.c:72: error: expected identifier or â(â before â}â token
shape2.c:73: error: expected identifier or â(â before âreturnâ
shape2.c:74: error: expected identifier or â(â before â}â token
Please post an updated version of your code so we may look at it. Just seeing the errors doesn't help in this scenario.
I assume "before â}â token" was because you had one too many } brackets and that return 0 statement was outside of your main function.
Based on that assumption one could assume that "before â)â token" indicates that you have a loop, conditional, and/or switch statement with one too many ) parenthesis.
Try looking harder at that.
If you're using vim on your remote machine then you may want to enable some options such as syntax highlighting, autoindenting, other stuff with the following vim commands.
Code:
:set showmode
:set ruler
:set number
:set background=dark
:syntax on
:set autoindent
As I understand it Putty is a terminal emulator for ssh communication. This is not the best tool for source code editing. Can you find an editor (such as notepad++ - previously mentioned) you may then find that the indentation problem that you are having when posting here goes away. Secondly, as a programmer you need to know what tools you have available and use the right ones. You can't be a carpenter if the only tool you use is a hammer.
Can you break the code down to smaller sub-problems. Tackle each sub-problem one at a time rather than trying to solve everything at once. I don't know what your background is, are you learning by yourself or at school / college? Do you have a text book, are you using any online tutorials?
74 lines of code
one while loop
ten for loops (with a maximum depth of 3 levels of nesting)
one if conditional
three switch conditionals
Without looking further that tells me that you need to go back to the design and think what it is you want to do. A total of eleven loops in a single function indicates a fundamental problem with your design.
Now looking at your code you have a while loop which will never be broken out of so all the code that follows will never be executed so is redundant until you sort out the while loop issue. So a gentle piece of advice remove all the other code and use that while loop as your starting point and then think about the design.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.