Created
June 7, 2018 20:51
-
-
Save Faliszek/5a44e158651503f0c643619fa6749ae9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <string.h> | |
#define N 10 | |
#define STRING_LENGTH 50 | |
struct Student | |
{ | |
char Name[STRING_LENGTH]; | |
char Surname[STRING_LENGTH]; | |
double Degree; | |
struct Student *next; | |
}; | |
char Names[9][STRING_LENGTH + 1] = {"Jacek", "Tomek", "Ala", "Mojżesz", "Achilles", "Maciek", "Janek", "Mateusz", "Micheal"}; | |
char Surnames[4][STRING_LENGTH + 1] = {"Nowak", "Kowalski", "Jasiołek", "Kopacz"}; | |
void CreateArray(struct Student *array, int length) | |
{ | |
int i; | |
array = (struct Student *)malloc(sizeof(struct Student) * length); | |
time_t zarodek; | |
srand(time(&zarodek)); | |
for (i = 0; i < length; i++) | |
{ | |
int nameInt = rand() % 9; | |
int surnameInt = rand() % 4; | |
int Od = 2; | |
int Do = 5; | |
double Degree = rand() % (Do + 1 - Od) + Od; | |
array[i].Degree = Degree; | |
strcpy(array[i].Surname, Surnames[surnameInt]); | |
strcpy(array[i].Name, Names[nameInt]); | |
} | |
} | |
void PrintArray(struct Student *array, int length) | |
{ | |
int i; | |
for (i = 0; i < length; i++) | |
{ | |
printf("%s", array[i].Name); | |
} | |
} | |
int main() | |
{ | |
struct Student *tab; | |
CreateArray(tab, N); | |
PrintArray(tab, N); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment