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

Anyone know how to program in C??


dux

Recommended Posts

Yeah

Are you passing a pointer to the array or are you passing the array? And what are you trying to do exactly

 

 

post your code. let's see

is putting an '&' before the variable name enough of a pointer? pointer variables will be my undong i swear

my code is messy so i dialled it way back and this is the logic im trying to use that wont work:

 

#include <stdio.h>
 
void main()
{
    double numbers[]= {1,2,3,4};
    void printNumbers(numbers);
}
 
 
void printNumbers(double no[])
{
    printf("%f and %f and %f and %f", no[0], no[1], no[2], no[3]);
}
Link to comment
Share on other sites

 

is putting an '&' before the variable name enough of a pointer? pointer variables will be my undong i swear

my code is messy so i dialled it way back and this is the logic im trying to use that wont work:

 

#include <stdio.h>
 
void main()
{
    double numbers[]= {1,2,3,4};
    void printNumbers(numbers);
}
 
 
void printNumbers(double no[])
{
    printf("%f and %f and %f and %f", no[0], no[1], no[2], no[3]);
}

 

 

Do you have to make a separate print method? I feel like it'd just be a lot easier to do it in main

Is there are reason you are using double over int? just curious because your example only has ints lol

 

Anyway those questions are irrelevant main should return an int. just put return 0 at the end of your main. I feel like that's your only problem lol

 

edit: idk if i made myself clear but main should be

 

int main(){

~code~

 

return 0;

}

 

oh and also get rid of the void before calling printNumbers function

Link to comment
Share on other sites

Do you have to make a separate print method? I feel like it'd just be a lot easier to do it in main

Is there are reason you are using double over int? just curious because your example only has ints lol

 

Anyway those questions are irrelevant main should return an int. just put return 0 at the end of your main. I feel like that's your only problem lol

yeah its required for the assignment loool if it wasnt id be so over this :rlytearpls:

and my numbers are meant to be doubles but i changed the values for simplicitys sake

this is what happens when i execute it:

 
Process returned 1 (0x1)   execution time : 0.350 s
Press any key to continue.
 
like nothing even shows up but that message? is the "returned 1" the way of saying somethings wrong?
Link to comment
Share on other sites

 

yeah its required for the assignment loool if it wasnt id be so over this rlytearpls.png

and my numbers are meant to be doubles but i changed the values for simplicitys sake

this is what happens when i execute it:

 
Process returned 1 (0x1)   execution time : 0.350 s
Press any key to continue.
 
like nothing even shows up but that message? is the "returned 1" the way of saying somethings wrong?

 

 

Sorry i edited, in your code get rid of the void so like

int main()
{
    double numbers[]= {1,2,3,4};
    printNumbers(numbers);
return 0;
}

 

You need the void when writing your function not calling it since that's just specifying the return type

Link to comment
Share on other sites

Sorry i edited, in your code get rid of the void so like

 

You need the void when writing your function not calling it since that's just specifying the return type

still broke :'(((

should i try using pointers?

Link to comment
Share on other sites

still broke :'(((

should i try using pointers?

 

how weird i literally wrote out the code myself and it works fine lol did you include the right libraries?

like 

 

#include<stdio.h>

 

Here's mine it's literally the same as yours (you shouldn't need stdlib.h i just always include out of habit)

6FF6anU.png

HxNMBLb.png

Link to comment
Share on other sites

 

is putting an '&' before the variable name enough of a pointer? pointer variables will be my undong i swear

my code is messy so i dialled it way back and this is the logic im trying to use that wont work:

 

#include <stdio.h>

 

void main()

{

double numbers[]= {1,2,3,4};

void printNumbers(numbers);

}

 

 

void printNumbers(double no[])

{

printf("%f and %f and %f and %f", no[0], no[1], no[2], no[3]);

}

Remove that void

Link to comment
Share on other sites

 

#include <stdio.h> void main(){    double numbers[]= {1,2,3,4};    void printNumbers(numbers);}  void printNumbers(double no[]){    printf("%f and %f and %f and %f", no[0], no[1], no[2], no[3]);}

 

two issues

 

1. you should declare the function printNumber before any use in the main function. Implicit declaration results in an error in C99, and a warning in C11. In addition, this implicit declaration here results in a type conflict error, which is the reason you code won't compile.

 

2. as pointed out by Romeo, you cannot precede a function call by a type (void in this case). This is a syntax error in any C standard.

 

 

once you fix these two there won't be any error or warning

Link to comment
Share on other sites

Ooops. I forgot another.

 

This was also mentioned above. The main function should return an int instead of void. This isn't an error, so you code will compile and run, but it results in a compiler warning.

Link to comment
Share on other sites

how weird i literally wrote out the code myself and it works fine lol did you include the right libraries?

like 

 

#include<stdio.h>

 

Here's mine it's literally the same as yours (you shouldn't need stdlib.h i just always include out of habit)

6FF6anU.png

HxNMBLb.png

im so stupid i didnt remove the void

 

Remove that void

 

 

two issues

 

1. you should declare the function printNumber before any use in the main function. Implicit declaration results in an error in C99, and a warning in C11. In addition, this implicit declaration here results in a type conflict error, which is the reason you code won't compile.

 

2. as pointed out by Romeo, you cannot precede a function call by a type (void in this case). This is a syntax error in any C standard.

 

 

once you fix these two there won't be any error or warning

thank youuu coding messiahs rlytearpls.pngahmagahplz.png

 

this is closer to my real code and this wont even run. like it just crashes

 

 

 

[size=4][background=#ffffff]#inclu[/size][/background]de <stdio.h>#include <math.h>typedef struct{    char *name;    double u, m0, q; //initial velocity, initial mass, fuel consumption rate} ROCKET;void main(){    ROCKET rockets[2] = { {"Rocket 1", 2000.0, 150000.0, 2700.0}, {"Rocket 2", 1596.0, 300000.0, 5367.0} };    selectRocket(rockets);}void selectRocket(ROCKET are[]){    int rocketNo;    printf("%s: u = %f m0 = %f q = %f\n", are[0].name, are[0].u, are[0].m0, are[0].q);    printf("%s: u = %f m0 = %f q = %f\n", are[1].name, are[1].u, are[1].m0, are[1].q);       printf("Select a Rocket from 1 to 4: ");}
wait wtf i changed some things it finally worked. its still crashing tho??
Link to comment
Share on other sites

 

#include <stdio.h>#include <math.h>typedef struct{    char *name;    double u, m0, q; //initial velocity, initial mass, fuel consumption rate} ROCKET;void main(){    ROCKET rockets[2] = { {"Rocket 1", 2000.0, 150000.0, 2700.0}, {"Rocket 2", 1596.0, 300000.0, 5367.0} };    selectRocket();}void selectRocket(ROCKET are[]){    int rocketNo;    printf("%s: u = %f m0 = %f q = %f\n", are[0].name, are[0].u, are[0].m0, are[0].q);    printf("%s: u = %f m0 = %f q = %f\n", are[1].name, are[1].u, are[1].m0, are[1].q);    printf("%s: u = %f m0 = %f q = %f\n", are[2].name, are[2].u, are[2].m0, are[2].q);    printf("%s: u = %f m0 = %f q = %f\n", are[3].name, are[3].u, are[3].m0, are[3].q);    printf("Select a Rocket from 1 to 4: ");}

 

1. again, implicit declaration of selectRocket results in a type conflict error. Declare it explicitly before the use in main

 

2. the argument list of your function call selectRocket() on line 15 doesn't match that of the declaration. This is a syntax error. But I suppose this is a typo and you meant selectRocket(rockets)

 

other than the above there are no more errors

 

3. again, main should return an int instead of void. This results in a warning.

 

4. the variable rocketNo on line 20 is declared but not used. This results in another compiler warning.

 

other than the above there are no more warnings

Link to comment
Share on other sites

1. again, implicit declaration of selectRocket results in a type conflict error. Declare it explicitly before the use in main

 

2. the argument list of your function call selectRocket() on line 15 doesn't match that of the declaration. This is a syntax error. But I suppose this is a typo and you meant selectRocket(rockets)

 

other than the above there are no more errors

 

3. again, main should return an int instead of void. This results in a warning.

 

4. the variable rocketNo on line 20 is declared but not used. This results in another compiler warning.

 

other than the above there are no more warnings

YES thanks!! it finally works but it crashes after execution lmao. idk whats up with that fixed it

im sorry to bother you thanks for all the help appreciate it so much

Link to comment
Share on other sites

ok my whole code (so far) is working now im about to cry thank you guys sososos much!! ive been at it for 3 hours now and it finally works warstarplz.png ill send you won or smth

lmaoo no prob, that's not necessary but actually some upvotes would be nice (≖ᴗ≖๑)

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