ola estou a fazer um programa em "C" ke le num ficheiro e grava as palavras encontradas num outro ficheiro. Mas no meu codigo ele nao chega a gravar em condiçoes. Alguem poderia me ajudar ate as 12:00 de 11/06/08.
O codigo esta assim.
[/SIZE]
O codigo esta assim.
Código:
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]<stdafx.h>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]<stdio.h>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]<string.h>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]<stdlib.h>[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]//#define MALLOC(x) ((x *) malloc (sizeof(x)))[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=white]contador,opcao,i;[/COLOR][/SIZE]
[SIZE=2]FILE *ficheiro,*fx;[/SIZE]
[SIZE=2][COLOR=#0000ff]char[/COLOR][/SIZE][SIZE=2][COLOR=white] temp[80],nome[1],ch,gravar[20];[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]char[/COLOR][/SIZE][SIZE=2][COLOR=#000000] [COLOR=white]cp[]=[/COLOR][/COLOR][/SIZE][SIZE=2][COLOR=white]" "[/COLOR][/SIZE][SIZE=2][COLOR=white];/* declaraçao a espaço em branco*/[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] main()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff]do[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n Menu de Opcoes \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n 1-Sumario de estatistica \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n 2-estatistica por palavra \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n 3-guardar Informacao \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n Insira a opcao que deseja \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]scanf ([/SIZE][SIZE=2][COLOR=#a31515]" %d"[/COLOR][/SIZE][SIZE=2],&opcao);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](opcao<=0 || opcao>3);[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](opcao == 1){[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n Por favor introduza o nome do ficheiro com sua extensao \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]scanf([/SIZE][SIZE=2][COLOR=#a31515]"%s"[/COLOR][/SIZE][SIZE=2],&nome);[/SIZE]
[SIZE=2]ficheiro = fopen(nome,[/SIZE][SIZE=2][COLOR=#a31515]"r"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] ((ficheiro) == NULL)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n Impossivel abrir o ficheiro \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]fx = fopen([/SIZE][SIZE=2][COLOR=#a31515]"gravar.txt"[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#a31515]"w+"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] ((fx) == NULL)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]printf ([/SIZE][SIZE=2][COLOR=#a31515]"\n\n Impossivel abrir o ficheiro \n\n"[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]ch=getc(ficheiro);[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2][COLOR=white](ch!=EOF)[/COLOR][/SIZE]
[SIZE=2][COLOR=white]{[/COLOR][/SIZE]
[SIZE=2]i=0;[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](ch!=cp[0] && ch!=EOF && ch!=[/SIZE][SIZE=2][COLOR=#a31515]'\n'[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]temp[i]=ch; [/SIZE]
[SIZE=2]ch=getc(ficheiro);[/SIZE]
[SIZE=2]i++;[/SIZE]
[SIZE=2]printf([/SIZE][SIZE=2][COLOR=#a31515]"%c"[/COLOR][/SIZE][SIZE=2],ch);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]temp[i]=[/SIZE][SIZE=2][COLOR=#a31515]'\0'[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]ch=getc(ficheiro);[/SIZE]
[SIZE=2]fprintf(fx,[/SIZE][SIZE=2][COLOR=#a31515]"%c"[/COLOR][/SIZE][SIZE=2],ch);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}
Última edição pelo moderador: