malloc free malloc free int sum(int a[4]) { return a[0] + a[1] + a[2] + a[3]; int main() { int b[4] = {1, 2, 3, 4}; printf("%d\n", sum(b)); return 0;
\ \t \n \r \r\n \r
string char* \0 a l m a \0
"alma" \0 "" int main() { char* s = "alma"; printf("%s\n", s); return 0; 'a' '\t' ''
string strlen strcmp strcpy strcat sprintf \0 char* \0
iconv \r \n fscanf fgets fgetc fread
\t
fscanf
void read_matrix(file* f, double* m, int cols, int rows) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { fscanf(f, "%lf", &m[i * cols + j]); void write_matrix(file* f, double* m, int cols, int rows) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { fprintf(f, "%f ", m[i * cols + j]); fprintf(f, "\n"); double* alloc_matrix(int cols, int rows) { double* m = (double*)malloc(cols * rows * sizeof(double)); if (m == 0) { printf("memory allocation error.\n"); exit(-1); return m; m cols rows
double struct matrix { double* m; int cols; int rows; ;
struct matrix{ double* m; int cols; int rows; ; void read_matrix(file* f, struct matrix mat) { for (int i = 0; i < mat.rows; i++) { for (int j = 0; j < mat.cols; j++) { fscanf(f, "%lf", &mat.m[i * mat.cols + j]); void write_matrix(file* f, struct matrix mat) { for (int i = 0; i < mat.rows; i++) { for (int j = 0; j < mat.cols; j++) { fprintf(f, "%f ", mat.m[i * mat.cols + j]); fprintf(f, "\n"); struct matrix alloc_matrix(int cols, int rows) { struct matrix mat; mat.cols = cols; mat.rows = rows; mat.m = (double*)malloc(cols * rows * sizeof(double)); if (mat.m == 0) { printf("memory allocation error.\n"); exit(-1); return mat; struct
struct struct matrix typedef struct matrix { double* m; int cols; int rows; matrix_t; matrix_t sizeof()
typedef struct matrix { double* m; int cols; int rows; matrix_t; void read_matrix(file* f, matrix_t mat) { for (int i = 0; i < mat.rows; i++) { for (int j = 0; j < mat.cols; j++) { fscanf(f, "%lf", &mat.m[i * mat.cols + j]); void write_matrix(file* f, matrix_t mat) { for (int i = 0; i < mat.rows; i++) { for (int j = 0; j < mat.cols; j++) { fprintf(f, "%f ", mat.m[i * mat.cols + j]); fprintf(f, "\n"); matrix_t alloc_matrix(int cols, int rows) { matrix_t mat; mat.cols = cols; mat.rows = rows; mat.m = (double*)malloc(cols * rows * sizeof(double)); if (mat.m == 0) { printf("memory allocation error.\n"); exit(-1); return mat; struct
matrix_t alloc_matrix(int cols, int rows) { matrix_t mat; mat.cols = cols; mat.rows = rows; mat.m = (double*)malloc(cols * rows * sizeof(double)); if (mat.m == 0) { printf("memory allocation error.\n"); exit(-1); return mat; matrix_t
void alloc_matrix(matrix_t* mat) { mat->m = (double*)malloc(mat->cols * mat->rows * sizeof(double)); if (mat->m == 0) { printf("memory allocation error.\n"); exit(-1); matrix_t matrix_t* -> int main() { matrix_t m; m.cols = 5; m.rows = 10; alloc_matrix(&m);
int double double float int short float double typedef typedef létező_típus új_név;
typedef typedef int index_t; typedef double elem_t; typedef struct matrix { elem_t* m; index_t cols; index_t rows; matrix_t; void read_matrix(file* f, matrix_t mat) { for (index_t i = 0; i < mat.rows; i++) { for (index_t j = 0; j < mat.cols; j++) { fscanf(f, "%lf", &mat.m[i * mat.cols + j]); void write_matrix(file* f, matrix_t mat) { for (index_t i = 0; i < mat.rows; i++) { for (index_t j = 0; j < mat.cols; j++) { fprintf(f, "%f ", mat.m[i * mat.cols + j]); fprintf(f, "\n"); matrix_t alloc_matrix(index_t cols, index_t rows) { matrix_t mat; mat.cols = cols; mat.rows = rows; mat.m = (elem_t*)malloc(cols * rows * sizeof(elem_t)); if (mat.m == 0) { printf("memory allocation error.\n"); exit(-1); return mat;
first data pointer data pointer data pointer NULL struct hallg { char neptun[10]; char nev[50]; ; struct hallg_list { struct hallg* data; struct hallg_list* next; ; typedef struct hallg hallg_t; typedef struct hallg_list hallg_list_t;
listaelem* void print_list(hallg_list_t* first) { for (hallg_list_t* i = first; i; i = i->next) { printf("%s\n", i->data->nev);
void append_list(hallg_list_t* last, hallg_list_t* n) { last->next = n; n->next = NULL;
void insert_list(hallg_list_t* item, hallg_list_t* n) { n->next = item->next; item->next = n; append_list NULL
int main() { // Hallgatok letrehozasa hallg_t h1 = {"f83id7", "Kiss Virag"}; hallg_t h2 = {"c7hs7f", "Toth Erika"}; hallg_t h3 = {"a7jc74", "Kovacs Peter"}; // Listaelemek letrehozasa hallg_list_t n1 = {&h1, NULL}; hallg_list_t n2 = {&h2, NULL}; hallg_list_t n3 = {&h3, NULL}; // Lista osszeallitasa append_list(&n1, &n2); append_list(&n2, &n3); print_list(&n1); printf("\n"); // Uj hallgato hallg_t h4 = {"sd34f2", "Horvath Gabor"}; hallg_list_t n4 = {&h4}; insert_list(&n2, &n4); print_list(&n1); printf("\n"); return 0;