Artöm
Variable name if you like
Artöm
void f(type name); - 1 arg function
struct s is type, arg is name
Anonymous
Anonymous
this is the orginal function
Anonymous
then you get a struct like this
Anonymous
Artöm
So?
Anonymous
then they passed use the struct as a parameter to replace what was there originally
Anonymous
but whats the f, there is no member of the struct called f, and its suppse to take four arguments
Anonymous
these arguments are in the struct , i understand, but what is that f for
Ilya
Anonymous
pms?
Artöm
Ilya
pms?
This is name of parameter
Artöm
In the function above f is argument of type fish
Artöm
Then you can do f.something to get data fron it
Anonymous
there is no f struct
Anonymous
Anonymous
they make a variable called snappy , it holds 4 members of data
Anonymous
then they pass snappy as a parameter direction to the functions when they call it
Artöm
Artöm
Copy of snappy
Anonymous
Copy of snappy
yea i get that , i talking about the parameter when you create the function
Anonymous
there is an f
Anonymous
what is the f for
Artöm
Name man
Artöm
You have snappy here. A variable
Artöm
And f there
Anonymous
what
Artöm
Did you like learned functions?
Anonymous
Anonymous
when they declare and define the function they use struct fish f
Anonymous
what is the f .
Artöm
Im struggling to explain it since its clear as a day for me
Artöm
Anonymous
you are not explaining it clearly
Artöm
Do you know what function argument is?
Anonymous
Anonymous
but isnt the struct itself the argument
Artöm
Write me a function which gets a number snd returns it
Artöm
Simply that
Anonymous
int ass(int t){return t};
Artöm
Now you have
int shit = 1529;
call the function
Anonymous
but int declares the data type as struct fish declares the data type
Artöm
Anonymous
ass(shit)
Artöm
Anonymous
thats the variable name
Artöm
Exactly as f in function above
Artöm
Same thing
Anonymous
Same thing
#include <stdio.h>
#include "functions.h"
int main(){
struct fish snappy;
struct fish johnny;
snappy = {"snappy","Piranha", 69,4};
johnny = {"johnny","Snapper", 32 , 12};
catalog(snappy);
label(snappy);
catalog(johnny);
label(johnny);
return 0;
}
Anonymous
this is my main file
Anonymous
struct fish {
const char *name;
const char *species;
int teeth;
int age;
};
void catalog(struct fish f);
void label(struct fish f);
Anonymous
this is in the header
Anonymous
#include <stdio.h>
#include "functions.h"
void catalog(struct fish f){
printf("%s is a %s with %i teeth. He is %i\n",name, species, teeth, age);
}
void label(struct fish f){
printf("Name:%s\nSpecies:%s\n%i years old, %i teeth\n",name, species, teeth, age);
}
Artöm
Anonymous
this is a separate file that defines the function
Artöm
Anonymous
https://pastebin.com/xt8Nai34
Anonymous
@das_3sz3tt look at this and tell me what i am doing wrong
Anonymous
its compiling now , but my other question lets say you want to organize it into different documents, like a main document, a header document where you declare functions, and a function.c where you define your functions, where do you place the struct
Anonymous
do you declare and define in the header file , or only declare, and define it in a sperate c file
Artöm
Artöm
Anonymous
Anonymous
yea the f.name part the book didnt explain to well but it reminds me of classes in c++ where you would make a object for a class and access the class members using the dot operator
Anonymous
@das_3sz3tt
Artöm
Yeah its same
Artöm
In structs you have bunch of data without functions
Israel
Someone here works with GUI on C++?? Wich are the best IDE's for make GUI based on your experience?
Artöm
qtcreator
Anonymous
this is my makefile
Anonymous
everything works well now thanks
Artöm
Anonymous
@MasterZiv you know
if i have two members of a stuct like this : const char *name;
const char *species; can i use scanf to define the members of a new struct variable
Artöm