LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-10-2010, 08:06 PM   #31
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0

I've spent over 20 hours on this code trying to figure things out. I think you would be sick of it too.
 
Old 10-10-2010, 08:10 PM   #32
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
I've spent over 20 hours on this code trying to figure things out. I think you would be sick of it too.
You should have spent time reading the C99 standard. Again, the code shows you do not understand very basic stuff. So, read the C99 standard.
 
Old 10-10-2010, 08:11 PM   #33
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
What parts will help me? Assignments, commas, and switch statement? And where are the examples?
 
Old 10-10-2010, 08:20 PM   #34
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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.
 
1 members found this post helpful.
Old 10-10-2010, 08:27 PM   #35
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
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
 
Old 10-10-2010, 08:41 PM   #36
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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
Turn them off like
Code:
:set ruler!
:syntax off
:set background=light

Last edited by sag47; 10-10-2010 at 08:44 PM.
 
Old 10-10-2010, 08:43 PM   #37
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by boilers969 View Post
I'm on windows but I'm using Putty.
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?
 
Old 10-10-2010, 08:46 PM   #38
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
This is my updated version.

Code:
#include<stdio.h>

int main()
{
   while(1)
        {
        char shape=1;
        int row;
        printf("Enter shape type (s/h/f):");
        scanf("%c",&shape);
        printf("Enter shape length: ");
        scanf("%d",&row);
        if(row<=0)
        printf("Shape length cannot be negative. Try again\n");
        }
for(int s=1;)
{
   switch(shape)
   {
        case 1:
{
           int i,row;
           for(i=row;i>=1;i--)
                printf("*\n");
           break;
           }
   }
}
for(int h=2)
{
   switch(h)
   {
        case 2:
{
           int i,j,k,row,m;
           m=row;
           for(i=1 ; i<=m; i++)
           {
                for (j=1 ; j>=row; j--)
                   printf(" ");
{
                   for(k=1; k<=i; k=k+1)
                        printf("*");
                   printf("\n");
           }
        }
        break;
        }
   }
}
for(int f=3)
        switch(f)
        {
           case 3:
{
                int i,j,k,row,m;
                m=row;
                for(i=0;i<m;i++)
                {
                   printf("\n");
                   for(k=0;k<row;k++)
                        printf(" ");
                   for(j=0;j<=i;j++)
                        printf(" *");
                   row--;
                }
        }
}
printf("\n");
break;
}
}
return 0;
}
 
Old 10-10-2010, 08:50 PM   #39
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by graemef View Post
As I understand it Putty is a terminal emulator for ssh communication. This is not the best tool for source code editing.
vim can be used on a remote machine which is just as good as Notepad++.
 
Old 10-10-2010, 08:52 PM   #40
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
check the syntax for a for loop.
This is what you have: for(int s=1;)

Ask yourself:

What should a for loop look like?
How does the expected differ from the one coded here?
How should it be changed?

Last edited by graemef; 10-10-2010 at 09:07 PM. Reason: disable smilies
 
Old 10-10-2010, 08:56 PM   #41
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
graemef
I'm in college and they don't offer text for this class.
 
Old 10-10-2010, 09:03 PM   #42
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
A quick look at your code. You have:

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.
 
Old 10-10-2010, 09:07 PM   #43
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by boilers969 View Post
graemef
I'm in college and they don't offer text for this class.
You might want to look for a good text book. See the sticky at the top of this forum for some ideas.
 
Old 10-10-2010, 09:09 PM   #44
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Have you studied functions yet?

This problem is crying out for them, but if not don't worry it can be coded in a single function?
 
Old 10-10-2010, 09:11 PM   #45
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
My goal is to have the program keep running and never terminate unless a user enters a char other than s,h,f.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What kind of code has shapes in it? theKbStockpiler Programming 2 09-11-2010 01:33 AM
LXer: IntelliJ's Maia shapes up against Eclipse LXer Syndicated Linux News 0 05-29-2009 11:01 PM
Dual monitors, separate X displays; want firefox in both displays bforbes Linux - Desktop 7 10-15-2008 09:26 PM
redirect a program to 2 displays schneidz Programming 0 08-29-2006 11:02 AM
Need benchmark program which displays bus speed. Arodef Linux - Software 2 07-15-2004 05:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration