int trig(int type, double *solutions)
As you are just passing in the address of one element in the call
trig(0, &solutions[19]);
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
int trig(int, double*);
double rad_deg(int, double);
main()
{
double solutions[19];
int i;
trig(0, &solutions[19]);
for(i=0; i<18; i++)
{
printf("\n Angle: %lf",solutions[i]);
}
}
int trig(int type, double *solutions[19])
{
//Function code here
}
double rad_deg(int type, double angle)
{
//Function code here
}
// testr.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
int trig(int, double*);
double rad_deg(int, double);
int main()
{
double solutions[19];
int i;
trig(0, &solutions[19]);
for(i=0; i<18; i++)
{
printf("\n Angle: %lf",solutions[i]);
}
}
int trig(int type, double *solutions)
{
//Function code here
return 0;
}
double rad_deg(int type, double angle)
{
//Function code here
return 0;
}
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
int trig(int type, double solutions[19]); /* <--- fixed the prototypes */
double rad_deg(int type, double angle);
main()
{
double solutions[19];
int i;
trig(0, solutions); /* just pass the array */
for(i=0; i<19; i++) /* upper limit < 19 instead of < 18 */
{
printf("\n Angle: %f",solutions[i]); /* %f instead of %lf */
}
}
int trig(int type, double solutions[19])
{
//Function code here
}
double rad_deg(int type, double angle)
{
//Function code here
}
main() {
}
// a comment
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
int trig(int, double *);
double rad_deg(int, double);
main()
{
double solutions[19];
int i;
trig(0, &solutions[19]);
for(i=0; i<18; i++)
{
printf("\n Angle: %lf",solutions[i]);
}
}
int trig(int type, double *solutions)
{
double angle;
int i;
if(type==0) //Sine
{ angle = rad_deg(1,0.0);
for(i=0; i<19; i++)
{
/* Add to the solutions array and return it to be output in main() */
*solutions[i] = sin(angle);
angle = rad_deg(1,(angle+10.0));
}
}
}
double rad_deg(int type, double angle)
{
//Type = 0 Convert from degrees to radians
//Type = 1 Convert from radians to degrees
if(type==0) return angle*(M_PI/180);
else return angle*(180/M_PI);
}
#include "stdafx.h"
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
int trig(int, double **);
double rad_deg(int, double);
int main()
{
double solutions[19];
double *pSolutions = solutions; /* use pointer to make life easier */
int i;
trig(0, &pSolutions);
for(i=0; i<18; i++)
{
printf("\n Angle: %lf",solutions[i]);
}
return 0;
}
int trig(int type, double **solutions)
{
double angle;
int i;
if(type==0) //Sine
{ angle = rad_deg(1,0.0);
for(i=0; i<19; i++)
{
/* Add to the solutions array and return it to be output in main() */
(*solutions)[i] = sin(angle);
angle = rad_deg(1,(angle+10.0));
}
}
return 0;
}
double rad_deg(int type, double angle)
{
//Type = 0 Convert from degrees to radians
//Type = 1 Convert from radians to degrees
if(type==0) return angle*(M_PI/180);
else return angle*(180/M_PI);
return 0;
}
#include "stdafx.h"
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#define MAX_SIZE 19 /* Use const for size */
void trig(int, double **);
double rad_deg(int, double);
int main() /* return iont */
{
double solutions[MAX_SIZE];
double *pSolutions = solutions; /* use pointer to make life easier */
int i;
trig(0, &pSolutions);
for(i=0; i<MAX_SIZE; ++i)
{
printf("\n Angle: %f",solutions[i]); /* use %f */
}
return 0; /* return something */
}
/* return void */
void trig(int type, double **solutions)
{
double angle;
int i;
if(type==0) //Sine
{ angle = rad_deg(1,0.0);
for(i=0; i<MAX_SIZE; i++)
{
/* Add to the solutions array and return it to be output in main() */
(*solutions)[i] = sin(angle);
angle = rad_deg(1,(angle+10.0));
}
}
}
double rad_deg(int type, double angle)
{
//Type = 0 Convert from degrees to radians
//Type = 1 Convert from radians to degrees
if(type==0) return angle*(M_PI/180);
else return angle*(180/M_PI);
}
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h> /* <--- add this include */
#include <math.h>
int trig(int, double **); /* <--- modified the function prototype */
double rad_deg(int, double);
int main() /* <--- main has to return int */
{
double *solutions = 0; /* <--- declare as pointer only - no size */
int i;
int size = trig(0, &solutions); /* <--- pass the address of the pointer and return the size */
for(i = 0; i < size; ++i) /* <--- use the returned size as loop limit */
{
printf("\n Angle: %f",solutions[i]); /* <--- use %f instead of %lf */
}
free(solutions); /* <--- clean up */
return 0; /* <--- return an int !! */
}
int trig(int type, double **solutions) /* <--- double** instead of double* */
{
double angle;
int i;
if(type==0) //Sine
{ angle = rad_deg(1,0.0);
*solutions = (double*) calloc(19, sizeof(double)); /* <--- allocate the array */
for(i=0; i<19; i++)
{
/* Add to the solutions array and return it to be output in main() */
(*solutions)[i] = sin(angle); /* <--- use () */
angle = rad_deg(1,(angle+10.0));
}
}
return 19; /* <--- return the size of the array */
}
double rad_deg(int type, double angle)
{
//Type = 0 Convert from degrees to radians
//Type = 1 Convert from radians to degrees
if(type==0) return angle*(M_PI/180);
else return angle*(180/M_PI);
}
int gn = 1;
void bar(int ** ppn_)
{
(*ppn_) = &gn;
}
void foo(int * pn_)
{
int *pn;
bar(&pn);
(*pn_) = *pn;
}
int main()
{
int n;
foo(&n);
return n;
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
how to connect an iphone application to mysql database | 10 | 188 | |
memory leak detection | 9 | 69 | |
How do I validate a simple fgets() statement in C programming? | 15 | 135 | |
libcurl - taking long time on curl_easy_perform | 11 | 352 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
22 Experts available now in Live!