tiag0 Posted November 16, 2009 at 11:33 AM Report Share #296454 Posted November 16, 2009 at 11:33 AM Boas pesoal, Ca ando eu as voltas com a programação em C e nao esta facil. Desta vez a minha duvida consiste em ler um ficheiro linha a linha, e dividir a linha por partes (esta parte ja consegui) e depois de ler gerar varios ficheiros onde possa escrever cada parte da string em cada um desses ficheiros gerados. Este e o codigo que ja tenho. Agradeço toda a ajuda. #include <stdio.h> #include <stdlib.h> const int TAM_BUFFER = 255; // quantidade de caracteres a serem lidos no buffer de cada vez int main(int argc, char *argv[]) { FILE *arquivo = fopen("nomes.txt", "r"); char buffer[TAM_BUFFER]; // testa se o arquivo foi aberto com sucesso if(arquivo != NULL){ // ler o conteúdo do arquivo e armazenar no buffer while(fgets(buffer, TAM_BUFFER, arquivo)){ //ler palavra a palavra char *token = NULL; token= strtok(buffer, "," ); while( token ) { printf("%s\n",token); token = strtok( NULL, "," ); } } fclose(arquivo); } else printf("Nao foi possivel abrir o arquivo."); printf("\n\n"); system("PAUSE"); return 0; } Link to comment Share on other sites More sharing options...
Baderous Posted November 16, 2009 at 10:38 PM Report Share #296580 Posted November 16, 2009 at 10:38 PM Indica as tuas dúvidas. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now