Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * File: main.c
- * Author: ryanr
- *
- * Created on 11 December 2018, 14:43
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*
- *
- */
- typedef struct person {
- char name[10][10];
- char surname[10][10];
- int age [10];
- } person_t;
- int main(int argc, char** argv) {
- FILE *inp; /* pointer to input file */
- FILE *outp; /* pointer to ouput file */
- char c;
- int word_count = 0;
- int char_count = 0;
- int s_word_count = 0;
- int s_char_count = 0;
- int input_status = 0;
- int i = 0;
- /* Prepare files for input or output */
- inp = fopen("in_file.txt", "r");
- person_t my_person;
- if (inp) {
- while ((c = fgetc(inp)) != EOF) {
- if (c == ' ' || c == '\r') {
- printf("\n");
- my_person.name[word_count][char_count] = '\0'; //Terminate the string
- char_count = 0; //Reset the counter.
- word_count++;
- }
- else {
- if (c >= '0' && c <= '9') {
- x = c - '0';
- my_person.age[i] = x;
- printf("Age: %d", my_person.age[i]);
- i++;
- }
- else {
- my_person.name[word_count][char_count] = c;
- printf("%c",my_person.name[word_count][char_count]);
- if (char_count < 19) {
- char_count++;
- }
- else {
- char_count = 0;
- }
- }
- }
- }
- }
- else {
- printf("No can do\n");
- }
- return (EXIT_SUCCESS);
- }
- //File Input
- Patrice 95
- Rio 96
- Marcus 78
- Wayne 69
- Alex 67
- Chris 100
- Nemanja 78
- //Current Output
- Patrice
- 95
- Rio
- 96
- Marcus
- 78
- Wayne
- 69
- Alex
- 67
- Chris
Advertisement
Add Comment
Please, Sign In to add comment