I cannot figure out how to fix my line 33 error. I believe I have successfully passed the variable "rows" but it then crashes!? Is it because it is defined incorrectly in the prototype?
//Libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
//Function Prototypes
char ReadInRecipientsName(void);
int OutputToFileORstdOut(void);
//int TreeToFile(void);
int AskUserForRows(void);
int CreateGreetingCard(int inVal, char a[75]);
//Begin
int main ()
{
//Local Declarations
char myString;
int choice;
int inVal = 0;
int choice2;
//Function Calls
myString = ReadInRecipientsName();
choice = OutputToFileORstdOut();
//choice2 = TreeToFile();
AskUserForRows();
inVal = CreateGreetingCard(inVal, myString);
//Displaying Stuff
//Exit Program
return 0;
}
//******************************************FUNCTIONS**************************************
//Function ReadInRecipientsName
char ReadInRecipientsName(void)
{
//Local Declarations
char a[75];
//User Prompt
printf("Please enter recipient: ");
scanf("%s", &a);
strlen("a");
//Return
return a[75];
}
//Function OutputToFileORstdOut
int OutputToFileORstdOut(void)
{
//Local Declarations
int b = 0;
//User Prompt
printf("Please enter a number greater than zero to output to the stdOut \n or enter a number less than zero to output to a file: ");
scanf("%d", &b);
//Return
return b;
}
//Function AskUserForRows
int AskUserForRows(void)
{
//Local Declarations
int localVal = 0;
//User Prompt
printf("Please enter the number of rows: ");
scanf("%d", &localVal);
//Return
return localVal;
}
//Function TreeToFile
int TreeToFile(void)
{
//Local Declarations
FILE* fp1;
char FileName1;
//User Prompt
printf("Please enter a name for your file. \n");
scanf("%s", &FileName1);
fp1 = fopen ("Libraries\Documents\FileName1.txt", "w");
printf("Your Christmas card was placed here at -> C:\\\\%s");
}
//Function CreateGreetingCard
int CreateGreetingCard(int inVal, char a[75])
{
//Local Declarations
int i;
int k;
int rows;
int location;
char myString[75];
//Work
//Top of border
for (i=1;i<=80;++i)
{
printf("_");
}
printf("\n");
//Chrsitmas Tree Build
for (k=1;k<=(rows-1);++k)
{
printf("|");
for (i=1;i<=79;++i)
{
if(((39-(k-1))<=i) && (i <= (39+(k-1))))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("|\n");
}
for (i=1;i<=81;++i) //tree base
{
if ((i==1) || (i==80))
{
printf("|");
}
if ((i>37)&&(i<41))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
if(rows<60)//empty space
{
for (k=(rows+1);k<=60;++k)
{
for (i=1;i<=81;++i)
{
if ((i==1) || (i==81))
{
printf("|");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
location = floor((float)(((19+strlen(myString))/2)));
for(i=1;i<=81;i++) //greeting message centered at bottom of card
{
if(i==1 || i==81)
{
printf("|");
}
if (i==(39-location))
{
printf("Happy Holidays:%s!!",myString);
i=i+(21+strlen(myString));
}
else
{
printf(" ");
}
}
printf("\n");
for(i=1;i<=80;++i)
{
printf("-");
}
}
AskUserForRows() returns an int, which you never assign to anything. You also have a local variable called inVal in your main which you've initialized to zero, and so you're passing zero to CreateGreetingCard().
Edit: You're not passing your string correctly to CreateGreetingCard(). You cannot return an array from a function. You can return a pointer to your array, and then pass it into your function.
Alternatively, you can use C++ strings, cin, cout, and avoid a lot of this mess... unless you have to write this using C headers only.