hi i wrote this program... it compiles with out any errors.. but when i try to run it in G++ compiller it gives the error "Segmentation Fault (core dump)"... i did a debug on visual c++
and it breaks at line 32 **which is marked below.
what the program does is, it takes 3 arguments, a number and 2 symbols,,, and draws a diamond...
it worked fine before i put the arguments to int main()..... can enyone point out the error for me please...i just have no friggin idea what went wrong
the codes are as follows......thanks :)...............
#include <iostream>
#include <stdio.h>
#include <ctype.h>
using namespace std;
void diamondrun(int * , char , char );
void diamonddraw (int , int , char , char );
// put arguments///////////////////
int main (int argc, char *argv[])
{
int hight;
char insymb, outsymb;
if ((argc > 4))
{
cout << '\n';
cout << "starting diamond" << '\n';
cout << "Syntax: diamond size outside inside" << '\n';
cout << "size must be integer > 0" << '\n';
cout << "outside and inside must be single chars" << '\n';
}
else
{
cout << '\n';
cout << "starting diamond" << '\n';
//printDiamond(value, *string1, *string2);
hight = atoi(argv[1]);//////////////////breaks here////////////////
insymb = *argv[2];
outsymb = *argv[3];
diamondrun(&hight,insymb,outsymb);
return 0;
}
}
// this function runs the diamonddraw function
void diamondrun(int *hightptr, char insymb, char outsymb)
{
int c; // counter
if (*hightptr % 2 == 1) // to check odd or even
{
// Draw the top half of the diamond, including the middle
for(c=1; c <= *hightptr; c+=2)
{
diamonddraw(*hightptr, c, insymb, outsymb);
}
// Draw the remaing half of the Diamond
for(c=*hightptr-2; c >= 1; c-=2)
{
diamonddraw(*hightptr, c, insymb, outsymb);
}
}
else // if the hight is even
{
// Draw the top half of the diamond, including the middle
for(c=1; c <= *hightptr; c+=2)
{
diamonddraw(*hightptr, c, insymb, outsymb);
}
// Draw the remaing half of the Diamond
for(c=*hightptr-3; c >= 0; c-=2)
{
diamonddraw(*hightptr, c, insymb, outsymb);
}
}
}
void diamonddraw(int width, int symbcount, char insymb, char outsymb)
{
int preSpaces = (width - symbcount) / 2;
int c;
// to print the spaces at the begining
for (c = 1; c <= (preSpaces); c++)
{
printf(" ");
}
for (c = 0; c <= (symbcount); c++)
{
printf("%c", &outsymb);// outline symbol
for (c = 2; c <= (symbcount-1); c++)
{
printf("%c", &insymb);// body symbol
}
//draw right side of big diamond :P
if (c!=2)
{
printf("%c", &outsymb);//outline symbol
}
}
// next line
printf("\n");//jumps to next line
}