Jump to content
OneHallyu Will Be Closing End Of 2023 ×
OneHallyu

Anyone know how to program in C??


dux

Recommended Posts

I can try to help you if you want.

yay! thank you :rlytearpls:

 

 

so basically im trying to use scanf in a function to store values in a structure variable. but no matter what i do, it seems its aways 0 stored/ nothing gets stored?? idk why

#include <stdio.h>#include <math.h>#define G 9.8#define NOCOLUMNS 10typedef struct{    double mass;    double drag;    double time;    double times[NOCOLUMNS];    double velocities[NOCOLUMNS];} USER_INPUT;void getInput(USER_INPUT *);void main(){    USER_INPUT input;    getInput(&input);    printf("%d", input.times[4]); //this line was just checking whether it worked or not}void getInput(USER_INPUT *demo){    printf("Enter the mass in kgs:\n");    scanf("%lf", &demo->mass);    printf("Enter the drag coefficient in kg/s:\n");    scanf("%lf", &demo->drag);    printf("Enter the time of interest in secs:\n");    scanf("%lf", &demo->time);    int n=0;    while(n<=NOCOLUMNS){            demo->times[n]= (demo->time)/NOCOLUMNS;            n++;    } 

 

 

Link to comment
Share on other sites

yay! thank you rlytearpls.png

 

 

so basically im trying to use scanf in a function to store values in a structure variable. but no matter what i do, it seems its aways 0 stored/ nothing gets stored?? idk why

#include <stdio.h>#include <math.h>#define G 9.8#define NOCOLUMNS 10typedef struct{    double mass;    double drag;    double time;    double times[NOCOLUMNS];    double velocities[NOCOLUMNS];} USER_INPUT;void getInput(USER_INPUT *);void main(){    USER_INPUT input;    getInput(&input);    printf("%d", input.times[4]); //this line was just checking whether it worked or not}void getInput(USER_INPUT *demo){    printf("Enter the mass in kgs:\n");    scanf("%lf", &demo->mass);    printf("Enter the drag coefficient in kg/s:\n");    scanf("%lf", &demo->drag);    printf("Enter the time of interest in secs:\n");    scanf("%lf", &demo->time);    int n=0;    while(n<=NOCOLUMNS){            demo->times[n]= (demo->time)/NOCOLUMNS;            n++;    } 

 

 

 

Try "demo->mass" instead of "&demo->mass" in "scanf". I think "demo->mass" is already the address of "mass" so there is no need for "&". If it doesn't work try "&(demo.mass)".

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Back to Top