Last active
August 29, 2015 14:05
-
-
Save crissilvaeng/4ac7aaee359549685ddd to your computer and use it in GitHub Desktop.
Shire Subway Sustem - Admin
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> //Pre-processor: Inclui biblioteca necessaria | |
#include <string.h> //Necessaria para o strcpy | |
#define ERROR_OPEN NULL | |
typedef struct //Cria tipo definido para estação | |
{ | |
char name[12]; //Char de 12 posições para armazenar o nome | |
int distance; //Inteiro para armazenar quilometros para a proxima estação | |
} tp_station; | |
main ( void ) | |
{ | |
FILE* subwayDB; //Ponteiro do tipo FILE para o arquivo no disco | |
const char nameFile[12] = "subway.txt"; //Constante com o nome do arquivo | |
const char openMode[4] = "w+"; //Constante com o modo de leitura | |
//subwayDB recebe o retorno da função fopen | |
subwayDB = fopen( nameFile, openMode ); //fopen recebe nome do arquivo e o metodo de leitura | |
if ( subwayDB != ERROR_OPEN ) //Se o valor de subway for diferente de NULL, o aquivo foi aberto | |
{ | |
//O arquivo foi aberto | |
tp_station station; | |
//Coloca na struct as informações de nome e distancia | |
strcpy( station.name, "Valley" ); | |
station.distance = 8; | |
fprintf ( subwayDB, "%s %d\n", station.name, station.distance ); | |
fclose ( subwayDB ); | |
} else { //Se o valor de subway for igual a NULL, o arquivo não foi aberto. | |
//O arquivo não foi aberto | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment