Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Header
- #ifndef HEADER_H_INCLUDED
- #define HEADER_H_INCLUDED
- #include <stdlib.h>
- #include <stdio.h>
- #include <limits.h>
- #include <string.h>
- struct info {
- int st;
- float nd;
- char *rd;
- };
- void find_info(char* file, struct info *data);
- void save(char *name, struct info *data);
- #endif
- ///Main
- #include "header.h"
- int main(/*int argc, char** argv*/)
- {
- /*if (argc < 2) {
- printf("Not enough arguments!\n");
- exit(0);
- }*/
- struct info *transfer = {0};
- transfer = (struct info*) malloc(sizeof(struct info));
- find_info("data.txt", transfer);
- save("generated.dat", transfer);
- free(transfer);
- return 0;
- }
- void save(char *name, struct info *data)
- {
- FILE* fp = fopen(name, "wb");
- (void)fwrite(&data, sizeof(data), 1, fp);
- //free(temp_string);
- //free(data.rd);
- fclose(fp);
- }
- ///Nd
- #include "header.h"
- void find_info(char* file, struct info *data)
- {
- FILE* fp = fopen(file, "r");
- if (fp == NULL) {
- (void)printf("File not found!\n");
- exit(1);
- }
- int temp_int = 0;
- float temp_float = INT_MIN;
- char *temp_string = NULL;
- while (fscanf(fp, "%d", &temp_int) != EOF) {
- temp_string = (char*)malloc(sizeof(char) * (temp_int + 1));
- if (temp_string == NULL) {
- (void)printf("Memory not allocated!\n");
- exit(2);
- }
- (void)fscanf(fp, " | %s | %f\n", temp_string, &temp_float);
- if (temp_float > data->st) {
- data->st = temp_int;
- data->nd = temp_float;
- data->rd = temp_string;
- (void)printf("%d | %s | %f\n", data->st, data->nd, data->rd);
- }
- }
- free(temp_string);
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement