Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EXAMPLE OF NORMAL STRUCT
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- struct pokemon {
- int dexNo;
- char name[11];
- char type1[8];
- char type2[8];
- bool shiny;
- };
- int main(void) {
- struct pokemon pk1;
- pk1.dexNo = 1;
- strcpy(pk1.name, "Bulbasaur"); //The '.' in pk1.name is called the DIRECT OPERATOR
- strcpy(pk1.type1, "Grass");
- strcpy(pk1.type2, "Poison");
- pk1.shiny = false;
- printf("The pokemon you caught was %s, which has a pokedex number of %d, has the type(s) %s, and is ", pk1.name, pk1.dexNo, strcat(pk1.type1, pk1.type2));
- if (pk1.shiny){
- printf("shiny.\n");
- }
- else {
- printf("not shiny.\n");
- }
- return 0;
- }
- EXAMPLE OF STRUCT USING TYPEDEF
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- typedef struct pokemon {
- int dexNo;
- char name[11];
- char type1[8];
- char type2[8];
- bool shiny;
- } POKEMON;
- int main(void) {
- POKEMON pk2;
- pk2.dexNo = 2;
- strcpy(pk2.name, "Ivysaur");
- strcpy(pk2.type1, "Grass");
- strcpy(pk2.type2, "Poison");
- pk2.shiny = true;
- printf("The pokemon you caught was %s, which has a pokedex number of %d, has the type(s) %s, and is ", pk2.name, pk2.dexNo, strcat(pk2.type1, pk2.type2));
- if (pk2.shiny){
- printf("shiny.\n");
- }
- else {
- printf("not shiny.\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement