Last active
February 11, 2016 03:46
-
-
Save macecchi/b94b28c70ecc44a6ca68 to your computer and use it in GitHub Desktop.
Converter planilha CSV pro input do BOCA
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> | |
#define LINE_SIZE 500 | |
#define USER_NUMBER 2100 | |
int main(void) { | |
FILE* f = NULL; | |
FILE* fexit = NULL; | |
char line[LINE_SIZE]; | |
char nome[50]; | |
int dre; | |
int read = 0; | |
f = fopen("alunos.csv", "r"); | |
fexit = fopen("turma.txt", "w"); | |
if (f == NULL) { | |
printf("Erro abrindo arquivo de turma alunos.csv.\n"); | |
return 10; | |
} | |
fprintf(fexit, "[user]\n"); | |
while (fgets(line, LINE_SIZE, f) != NULL) { | |
printf("%s\n", line); | |
if (sscanf(line, "%[^,],%d", nome, &dre) < 2) { | |
printf("Erro lendo\n"); | |
return 20; | |
} else { | |
//printf("Leu aluno '%s' com DRE '%d'\n", nome, dre); | |
fprintf(fexit, "usernumber=%d\n", read+USER_NUMBER); | |
fprintf(fexit, "username=%d\n", dre); | |
fprintf(fexit, "userpassword=%d\n", dre); | |
fprintf(fexit, "userfullname=%s\n", nome); | |
fprintf(fexit, "userenabled=t\n"); | |
fprintf(fexit, "usermultilogin=t\n"); | |
fprintf(fexit, "usersitenumber=1\n"); | |
read++; | |
} | |
fprintf(fexit, "\n"); | |
} | |
printf("%d alunos lidos e exportados para o arquivo turma.txt\n", read); | |
fclose(f); | |
fclose(fexit); | |
return 0; | |
} | |
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
JOAO SILVA | 1234567890 | |
---|---|---|
JOSE SOUZA | 3212425653 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment