[langage pascal] [probleme fonction eof]
Julien
-
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour a tous... voila apres maintes et maintes essais je me vois dans l'obligation de venir sur mon gentil forum informatique vous exposez mon probleme.... effectivement , je dois copier le contenu d'un fichier [B]texte[/B] dans un tableau de [B]string[/B]... je voudrais qu'a chaque mot contenu dans le fichier soit allouée une case...je vous entend deja dire d'ici que c'est facile... mais pour un apprenti en programmation de 16ans c'est deja assez compliqué... voici donc mon code, le probleme est qu'il ne lit pas le dernier mot du fichier et donc ne lui alloue aucune case... j'ai aussi inclu un "write" qui permet de voir ce que contient vraiment le fichier.... :
[QUOTE][B]program test;[/B]
uses sysutils,crt;
const EMPLACEMENTFICHIER='C:\programmation\fichier.txt';
type
recordrecherche = record
mot : string;
numligne : integer;
numposmot : integer;
end;
tableau1 = array[1..1000000] of string;
tableau2 = array[1..1000000] of recordrecherche;
var car:char;
temporaire:string;
fichier: text;
tableaurecherche:tableau1;
tableaurecit:tableau2;
compteurmot:integer;
ok:boolean;
begin
assign (fichier, EMPLACEMENTFICHIER);
reset(fichier) ;
compteurmot:=1;
while ( not(eof(fichier) ) ) do
begin
read(fichier, car);
while (car <> ' ' ) do
begin
temporaire:= (temporaire+car);
read (fichier, car);
end;
tableaurecherche[compteurmot]:=(temporaire);
temporaire:=('');
writeln(tableaurecherche[compteurmot]); //pour verifier que le tableau est initialisé//
compteurmot:=(compteurmot+1);
end;
close(fichier);
end.[/QUOTE]
ca c'est pour le premier programme qui copie le fichier en un tableau de string.... et voici mon deuxieme code qui lui, copie le contenu d'un fichier de texte, dans un tableau de record à 3champs (un champ de mot : string, un champ de position de mot (pour savoir sa palce dans la ligne) et un champ de numero de ligne pour savoir a quelle ligne il est dans le texte ;) ) et la le probleme est plus ou moins similaire... disons que j'aimerai savoir ce qui cloche... en sachant que il faut absolument que cela m'affiche le mot, sa position dans la ligne et le numero de sa ligne... d'ou l'usage de 2compteur, un qui s'incremente avec le eoln (end of line) pour savoir quand on passe a une autre ligne... (mais mon end of line ne fonctionne pas)... enfin le voici, votre aide sera precieuse et me permettrait d'avancer... :
[QUOTE]program test;
uses sysutils,crt;
const EMPLACEMENTFICHIER='C:\Documents and Settings\Gilles\Mes documents\Mes fichiers reçus\fichier.txt';
type
recordrecherche = record
mot : string;
numligne : integer;
numposmot : integer;
end;
tableau1 = array[1..1000000] of string;
tableau2 = array[1..1000000] of recordrecherche;
var car:char;
temporaire:string;
fichier: text;
tableaurecherche:tableau1;
tableaurecit:tableau2;
compteurmot:integer;
compteurligne,avancementtableau:integer;
begin
assign (fichier, EMPLACEMENTFICHIER);
reset(fichier) ;
compteurmot:=1;
compteurligne:=1;
avancementtableau:=1;
while ( not(eof(fichier) ) ) do
begin
read(fichier, car);
while (car <> ' ' ) do
begin
temporaire:= (temporaire+car);
read (fichier, car);
end;
if (eoln(fichier)) then begin
compteurligne:=(compteurligne+1);
compteurmot:=1;
end;
tableaurecit[avancementtableau].mot:=(temporaire);
tableaurecit[avancementtableau].numligne:=(compteurligne);
tableaurecit[avancementtableau].numposmot:=(compteurmot);
temporaire:=('');
write(tableaurecit[avancementtableau].mot);
write(' ');write(tableaurecit[avancementtableau].numposmot);
write(' ');writeln(tableaurecit[avancementtableau].numligne);
compteurmot:=(compteurmot+1);
avancementtableau:=(avancementtableau+1);
end;
close(fichier);
end.[/QUOTE]
Merci a tous pour votre attention, au plaisir de vous lire, Julien.
[QUOTE][B]program test;[/B]
uses sysutils,crt;
const EMPLACEMENTFICHIER='C:\programmation\fichier.txt';
type
recordrecherche = record
mot : string;
numligne : integer;
numposmot : integer;
end;
tableau1 = array[1..1000000] of string;
tableau2 = array[1..1000000] of recordrecherche;
var car:char;
temporaire:string;
fichier: text;
tableaurecherche:tableau1;
tableaurecit:tableau2;
compteurmot:integer;
ok:boolean;
begin
assign (fichier, EMPLACEMENTFICHIER);
reset(fichier) ;
compteurmot:=1;
while ( not(eof(fichier) ) ) do
begin
read(fichier, car);
while (car <> ' ' ) do
begin
temporaire:= (temporaire+car);
read (fichier, car);
end;
tableaurecherche[compteurmot]:=(temporaire);
temporaire:=('');
writeln(tableaurecherche[compteurmot]); //pour verifier que le tableau est initialisé//
compteurmot:=(compteurmot+1);
end;
close(fichier);
end.[/QUOTE]
ca c'est pour le premier programme qui copie le fichier en un tableau de string.... et voici mon deuxieme code qui lui, copie le contenu d'un fichier de texte, dans un tableau de record à 3champs (un champ de mot : string, un champ de position de mot (pour savoir sa palce dans la ligne) et un champ de numero de ligne pour savoir a quelle ligne il est dans le texte ;) ) et la le probleme est plus ou moins similaire... disons que j'aimerai savoir ce qui cloche... en sachant que il faut absolument que cela m'affiche le mot, sa position dans la ligne et le numero de sa ligne... d'ou l'usage de 2compteur, un qui s'incremente avec le eoln (end of line) pour savoir quand on passe a une autre ligne... (mais mon end of line ne fonctionne pas)... enfin le voici, votre aide sera precieuse et me permettrait d'avancer... :
[QUOTE]program test;
uses sysutils,crt;
const EMPLACEMENTFICHIER='C:\Documents and Settings\Gilles\Mes documents\Mes fichiers reçus\fichier.txt';
type
recordrecherche = record
mot : string;
numligne : integer;
numposmot : integer;
end;
tableau1 = array[1..1000000] of string;
tableau2 = array[1..1000000] of recordrecherche;
var car:char;
temporaire:string;
fichier: text;
tableaurecherche:tableau1;
tableaurecit:tableau2;
compteurmot:integer;
compteurligne,avancementtableau:integer;
begin
assign (fichier, EMPLACEMENTFICHIER);
reset(fichier) ;
compteurmot:=1;
compteurligne:=1;
avancementtableau:=1;
while ( not(eof(fichier) ) ) do
begin
read(fichier, car);
while (car <> ' ' ) do
begin
temporaire:= (temporaire+car);
read (fichier, car);
end;
if (eoln(fichier)) then begin
compteurligne:=(compteurligne+1);
compteurmot:=1;
end;
tableaurecit[avancementtableau].mot:=(temporaire);
tableaurecit[avancementtableau].numligne:=(compteurligne);
tableaurecit[avancementtableau].numposmot:=(compteurmot);
temporaire:=('');
write(tableaurecit[avancementtableau].mot);
write(' ');write(tableaurecit[avancementtableau].numposmot);
write(' ');writeln(tableaurecit[avancementtableau].numligne);
compteurmot:=(compteurmot+1);
avancementtableau:=(avancementtableau+1);
end;
close(fichier);
end.[/QUOTE]
Merci a tous pour votre attention, au plaisir de vous lire, Julien.
A voir également:
- [langage pascal] [probleme fonction eof]
- Turbo pascal - Télécharger - Édition & Programmation
- Fonction si et - Guide
- Langage ascii - Guide
- My pascal - Télécharger - Édition & Programmation
- Dev pascal - Télécharger - Édition & Programmation