LinuxQuestions.org
Help answer threads with 0 replies.
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, 07:18 PM   #16
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0

Well for me it doesn't. I'm just asking for help.
 
Old 10-10-2010, 07:21 PM   #17
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
Well for me it doesn't. I'm just asking for help.
First read the C99 standard, then we'll deal with the copy->paste->indent problem.
 
Old 10-10-2010, 07:21 PM   #18
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
Well for some reason it doesn't work for me. I'm just asking for help.
 
Old 10-10-2010, 07:22 PM   #19
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
I'm not worried about that. I just want my program to compile.
 
Old 10-10-2010, 07:22 PM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
Well for some reason it doesn't work for me. I'm just asking for help.
Read the C99 standard first.
 
Old 10-10-2010, 07:24 PM   #21
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
I did. When you first posted it.
 
Old 10-10-2010, 07:27 PM   #22
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 boilers969 View Post
So i attempted it with 3 separate switch statements.

Code:
#include<stdio.h>

int main()
{
while(1){
char shape;
char s,h,f;
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(s)
{
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;
}
You're attacking this all wrong. First you need to indent like Nylex said.
Quote:
Originally Posted by Nylex
Again, it would help if you put indentation in.
Another issue that I have with you doing is your fancy for loops not using curly brackets {}. Although it is not programmatically incorrect it is a bad habit just like not indenting. The reason is you end up with code like this (directly pulled from your code):
Code:
for (j=1 ; j>=row; j--)
    printf(" ");
{
    for(k=1; k<=i; k=k+1)
        printf("*");
    printf("\n");
}
So in the future you should write your for loops like so which will make your code more accurate and easier to read if you're on a project with more than one person programming:
Code:
for(k=1; k<=i; k=k+1)
{
    printf("*");
}
That problem occurs at line 41 of your code which I will give you back fully indented. Make indenting a habit and your troubleshooting will get dramatically easier and you'll find that you can easily write accurate code the first time.

Code:
#include<stdio.h>

int main()
{
    while(1)
    {
        char shape;
        char s,h,f;
        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(s)
        {
            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;
}
Notice at the end:
Code:
}}
return 0;
}
That is not inside of your main function at all... indenting would have avoided that.

As for the rest of your code I think another member would better be able to help you using the indented version. I don't know how to program C. At least not outside your basic hello world or embedded circuits.

Last edited by sag47; 10-10-2010 at 07:30 PM.
 
Old 10-10-2010, 07:30 PM   #23
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 did. When you first posted it.
If so, justify according to the standard the following pieces of your code:


Code:
shape='s';
shape='h';
shape='f';
,
Code:
for(int s=1,int h=2,int f=3)
,
Code:
switch(s,h,f)
,
Code:
{int i,row;
for(i=row;i>=1;i--)
.
 
Old 10-10-2010, 07:30 PM   #24
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
Thanks sag47. Now if only I could figure out what's wrong.
 
Old 10-10-2010, 07:32 PM   #25
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
Thanks sag47. Now if only I could figure out what's wrong.
Justify every line of your code by paragraphs of C99 standard. Start from the ones mentioned in http://www.linuxquestions.org/questi...ml#post4123274 .
 
Old 10-10-2010, 07:35 PM   #26
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
Haha that's obviously why I'm on here. And your c99 standard isn't helping me.
 
Old 10-10-2010, 07:38 PM   #27
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
Since you're on Windows hopefully you're not using Notepad. Better to use something like Notepad++ which is what I formatted your code in around 15 seconds.
 
Old 10-10-2010, 07:48 PM   #28
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
... your c99 standard isn't helping me.
Then programming is a wrong thing for you to do. Your code shows that you either never read the standard or didn't bother to understand.
 
Old 10-10-2010, 07:55 PM   #29
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Original Poster
Rep: Reputation: 0
I'm on windows but I'm using Putty.
Sergei, i was hoping for help directly, not getting refered to a book.
 
Old 10-10-2010, 08:01 PM   #30
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
...
Sergei, i was hoping for help directly, not getting refered to a book.
And that's the problem. Various posters including myself pointed you to the exact places in your code which are hopelessly wrong. And you were given sources of info to get knowledge from.

Instead of reading and then asking you insist on being lazy and exploiting others. I.e. you are fiercely resiting reading and comprehending. In real life standards are sometimes 700 pages long and maybe longer. Nobody will hold your hand begging you to read.
 
1 members found this post helpful.
  


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 11:05 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