-
test code
i have this create_new function that seems to be right to me but i dont know how to test it. How would i call the function?
Code:
personal create_new()
{
personal temp;
printf("\nFist Name: ");
fgets(temp.F_name, sizeof temp.F_name, stdin);
printf("\nLast Name: ");
fgets(temp.L_name, sizeof temp.L_name, stdin);
printf("\nSalary: ");
scanf("%d", &temp.salary);
printf("\nMonth of birth: ");
scanf("%d", &temp.birth.Birth_month);
printf("\nDay of Birth: ");
scanf("%d", &temp.birth.Birth_day);
printf("\nYear of Birth: ");
scanf("%d", &temp.birth.Birth_year);
printf("\nAddress information...");
printf("\nStreet name: ");
fgets(temp.stuff.street, sizeof temp.stuff.street, stdin);
printf("\nCity: ");
fgets(temp.stuff.city, sizeof temp.stuff.city, stdin);
printf("\nState: ");
fgets(temp.stuff.state, sizeof temp.stuff.state, stdin);
printf("\nZip Code: ");
fgets(temp.stuff.zip, sizeof temp.stuff.zip, stdin);
return (temp);
}
-
Why don't you ask the person you got it from? :)
That function is not defined properly either. It is missing a type, and a parameter list (or if no parameters, then void)
~/
-
I hope this works for ya:
Code:
#include <stdio.h>
#include <stdlib.h>
/// STRUCTURES
struct Sbirth {
double Birth_year;
double Birth_month;
double Birth_day;
};
struct Sstuff {
char street[50];
char city[50];
char state[15];
char zip[10];
};
struct personal {
char F_name[50];
char L_name[50];
double salary;
struct Sbirth birth;
struct Sstuff stuff;
};
/// PROTOTYPE FUNCTIONS
struct personal create_new();
/// MAIN
int main() {
struct personal p = create_new();
printf("Hello %s", p.F_name);
return 0;
}
/// CREATE NEW PERSON
struct personal create_new() {
struct personal temp;
printf("\nFist Name: ");
fgets(temp.F_name, sizeof temp.F_name, stdin);
printf("\nLast Name: ");
fgets(temp.L_name, sizeof temp.L_name, stdin);
printf("\nSalary: ");
scanf("%d", &temp.salary);
printf("\nMonth of birth: ");
scanf("%d", &temp.birth.Birth_month);
printf("\nDay of Birth: ");
scanf("%d", &temp.birth.Birth_day);
printf("\nYear of Birth: ");
scanf("%d", &temp.birth.Birth_year);
printf("\nAddress information...");
printf("\nStreet name: ");
fgets(temp.stuff.street, sizeof temp.stuff.street, stdin);
printf("\nCity: ");
fgets(temp.stuff.city, sizeof temp.stuff.city, stdin);
printf("\nState: ");
fgets(temp.stuff.state, sizeof temp.stuff.state, stdin);
printf("\nZip Code: ");
fgets(temp.stuff.zip, sizeof temp.stuff.zip, stdin);
return (temp);
}
-
Kleid-0, you seem to be doing this a lot. Please do not post a whole bunch of source code that doesn't even answer the OP's question. No one learns anything when you just give them source code.
Once you've got a working function, you can call it in the following way:
Code:
variable1 = function1(parameter1, parameter2);
Everything is optional except for the function name and parentheses. If your function returns something, you can assign that variable to something by using the function on the right side of an assignment statement. To pass parameters into your function, you just place the code parameters, in order, delimited by commas, in between the parentheses.