5 Replies - 4485 Views - Last Post: 13 January 2013 - 09:32 PM Rate Topic: **--- 2 Votes

#1 usermayor07  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-January 13

segmentation fault(core dumped)right half pyramid using # in c

Posted 12 January 2013 - 12:07 AM

#incude <cs50.h>
#include <stdio.h>


Int main(void)

{  


  Int x;y;z;

  While(x<0)

       { 

          printf("enter number_");
          Scanf("%d"x);

       }

      

    for(y=o,y=x,y>,y--)
    for(z=0,z>=x,z++)
     {
       printf(" ");
       Print("#");
       Print("\n");
       return0;
    
      }

    


  }

This post has been edited by jimblumberg: 12 January 2013 - 07:59 AM
Reason for edit:: Added missing code tags. Please learn to use them.

Is This A Good Question/Topic? 0
  • +

Replies To: segmentation fault(core dumped)right half pyramid using # in c

#2 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1570
  • View blog
  • Posts: 2,991
  • Joined: 30-May 10

Re: segmentation fault(core dumped)right half pyramid using # in c

Posted 12 January 2013 - 01:21 AM

OK, where is the real code?
That stuff is just a mass of spelling mistakes (C is case sensitive), and syntax errors (for loops with no ; in them)

This doesn't crash (unless it's a buggy compiler), since it won't even compile.

And you forgot the [code][/code] tags.
Was This Post Helpful? 0
  • +
  • -

#3 usermayor07  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-January 13

Re: segmentation fault(core dumped)right half pyramid using # in c

Posted 12 January 2013 - 02:04 AM

View PostSalem_c, on 12 January 2013 - 01:21 AM, said:

OK, where is the real code?
That stuff is just a mass of spelling mistakes (C is case sensitive), and syntax errors (for loops with no ; in them)

This doesn't crash (unless it's a buggy compiler), since it won't even compile.

And you forgot the [code][/code] tags.



Ok
The typos was cos I typed these here on my mobile cos am away frm ma pc.
The code original code had the missing (for loop ; )and it compiled and prompted me for an input after running it but when I provided the input(number) and pressed enter,it says segmentation fault(core dumped).the compilar is not buggy.its the cs50 appliance for havard c programing classam.I will type the code again as it is on ma pc.pls kindly tell me what am doing wrong

#include <cs50.h>
#include <stdio.h>


Int main(void)


{

 Intx,y,z;


  While(x>0)
    {
      Printf("enter input_");
      Scanf("%d",x);
    }

      for( int z=x;z<=0;z--)

   {

     for( int y=0;y<=x;y++)

       {
        printf(" ");
        print("#");
        print("\");
        Return0;
       }
    }

}

This post has been edited by jimblumberg: 12 January 2013 - 08:00 AM
Reason for edit:: Added missing code tags. Please learn to use them.

Was This Post Helpful? 0
  • +
  • -

#4 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: segmentation fault(core dumped)right half pyramid using # in c

Posted 12 January 2013 - 02:15 AM

Scanf("%d",x);


scanf expects a pointer, so you need to pass the address of x, not the value of x.
Was This Post Helpful? 0
  • +
  • -

#5 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1570
  • View blog
  • Posts: 2,991
  • Joined: 30-May 10

Re: segmentation fault(core dumped)right half pyramid using # in c

Posted 12 January 2013 - 02:24 AM

> The typos was cos I typed these here on my mobile cos am away frm ma pc.
Stop wasting everyone's time then.

Post the ACTUAL code from your PC when you're next at your desk.

Because all we're going to do is pick up all the faults in your half-remembered code, which may not even have the real problem in it.
Was This Post Helpful? 3
  • +
  • -

#6 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: segmentation fault(core dumped)right half pyramid using # in c

Posted 13 January 2013 - 09:32 PM

Well, here are the errors that I noted. I have commented the corrections for your reference

#include <cs50.h>
#include <stdio.h>


Int main(void)


{

 Intx,y,z; //always spacing should be present between datatype and variables. Should be int x,y,z;


  While(x>0)
    {
      Printf("enter input_");
      Scanf("%d",x);  //scanf takes the format...scanf("format_specifier",&variable);
    }

      for( int z=x;z<=0;z--) //here the int is not necessary as you have already declared the variable z as integer

   {

     for( int y=0;y<=x;y++)//refer above comment and replace z by y

       {
        printf(" ");
        print("#"); //there is no function called print in C
        print("\");// refer above comment
        Return0; // spacing required between return and 0
       }
    }

}


Edit: typo

regards,
Raghav

This post has been edited by raghav.naganathan: 13 January 2013 - 09:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1