IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

[c++ Win32] Edit Control avec fopen


Sujet :

C++

  1. #1
    Membre confirmé
    Inscrit en
    Décembre 2007
    Messages
    67
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 67
    Par défaut [c++ Win32] Edit Control avec fopen
    Salut,
    Question sûrement stupide mais, je n’arrive pas depuis ce matin à afficher un texte « .txt » dans IDC_EDIT1 (Edit Control)

    Mon problème, c’est le retour à la ligne et la détection de la fin du fichier.

    Dans le fichier test.txt :
    0 0 0
    0 1 1
    1 0 1
    1 1 0

    et le programme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    	char temp[800];
    	int i=0;
    	char c;
    	const char* fichier;
    	fichier="test.txt";
    	FILE*   fp = NULL;
    	fp = fopen(fichier,"r");
     
    	 while (( c=fgetc(fp)) !=EOF)
    	{
    		//if(c=='\0') temp[i++]='\r\n';
    		temp[i++]=c;
    	}
     
    	if(fp) fclose(fp);
    	SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),temp);
    merci beaucoup
    @+

  2. #2
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 487
    Par défaut

    char temp[800];
    int i=0;
    char c;
    const char* fichier;
    strcpy(fichier,"test.txt");
    FILE* fp ;
    fp = fopen(fichier,"rt");

    while (( c=fgetc(fp)) >0)
    {
    //if(c=='\0') temp[i++]='\r\n';
    temp[i++]=c;
    }

    if(fp) fclose(fp);
    SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),temp);

  3. #3
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 487
    Par défaut

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    char temp[800];
    	int i=0;
    	char c;
    	const char* fichier;
    	strcpy(fichier,"test.txt");
    	FILE*   fp ;
    	fp = fopen(fichier,"rt");
     
    	 while (( c=fgetc(fp)) >0)
    	{
    		//if(c=='\0') temp[i++]='\r\n';
    		temp[i++]=c;
    	}
     
    	if(fp) fclose(fp);
    	SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),temp);[/QUOTE]

  4. #4
    Membre confirmé
    Inscrit en
    Décembre 2007
    Messages
    67
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 67
    Par défaut
    Salut,
    Le programme fonctionne, mais, j’ai toujours les mêmes problèmes
    @+

  5. #5
    Membre confirmé
    Inscrit en
    Décembre 2007
    Messages
    67
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 67
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    		char temp[50];
    		int i=0;
    		char c;
    		const char* fichier;
    		fichier="DATA\\Logiques\\OU-EXCLUSIF.txt";
    		FILE* fp ;
    		fp = fopen(fichier,"rt");
     
    		while (( c=fgetc(fp)) !=EOF)
    		{
    			if(c=='\n') temp[i++]='\r';
    		temp[i++]=c;
    		}
     
    		if(fp) fclose(fp);
    		SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),temp);

    Il y a du mieux, j’obtiens :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    0 0  0
    0 1  1
    1 0  1
    1 1  0ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ3kîÌ(û

  6. #6
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 487
    Par défaut
    Citation Envoyé par swo.line Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    		char temp[50];
    		int i=0;
    		char c;
    		const char* fichier;
    		fichier="DATA\\Logiques\\OU-EXCLUSIF.txt";
    		FILE* fp ;
    		fp = fopen(fichier,"rt");
    
    		while (( c=fgetc(fp)) !=EOF)
    		{
    			if(c=='\n') temp[i++]='\r';
    		temp[i++]=c;
    		}
                     temp[i]='\0';
    		if(fp) fclose(fp);
    		SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),temp);

    Il y a du mieux, j’obtiens :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    0 0  0
    0 1  1
    1 0  1
    1 1  0ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ3kîÌ(û
    Tu doit ajouter le ‘\0’

  7. #7
    Membre confirmé
    Inscrit en
    Décembre 2007
    Messages
    67
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 67
    Par défaut
    Impeccable merci

  8. #8
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 487
    Par défaut
    Citation Envoyé par swo.line Voir le message
    Impeccable merci
    N oubli pas de mettre

  9. #9
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 392
    Par défaut
    "rt" n'est pas portable.
    "r" suffit, si on n'a pas fait n'importe quoi avec le projet.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  10. #10
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 487
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    "rt" n'est pas portable.
    "r" suffit, si on n'a pas fait n'importe quoi avec le projet.

    D’après mes connaissances rt est portable

  11. #11
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 392
    Par défaut
    Tes connaissances ne doivent pas s'appeler n1256.pdf...
    Citation Envoyé par standard C99
    The argument mode points to a string. If the string is one of the following, the file is
    open in the indicated mode. Otherwise, the behavior is undefined.
    r open text file for reading
    w truncate to zero length or create text file for writing
    a append; open or create text file for writing at end-of-file
    rb open binary file for reading
    wb truncate to zero length or create binary file for writing
    ab append; open or create binary file for writing at end-of-file
    r+ open text file for update (reading and writing)
    w+ truncate to zero length or create text file for update
    a+ append; open or create text file for update, writing at end-of-file
    r+b or rb+ open binary file for update (reading and writing)
    w+b or wb+ truncate to zero length or create binary file for update
    a+b or ab+ append; open or create binary file for update, writing at end-of-file
    Même cette clause dit "implementation-defined", donc non-portable:
    237) If the string begins with one of the above sequences, the implementation might choose to ignore the
    remaining characters, or it might use them to select different kinds of a file (some of which might not
    conform to the properties in 7.19.2).
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. win32 api - EDIT control
    Par opc0de dans le forum C++
    Réponses: 0
    Dernier message: 25/04/2011, 16h51
  2. [WIN32][VC60]Pb avec SetLayeredWindowAttributes
    Par Invité dans le forum MFC
    Réponses: 21
    Dernier message: 23/08/2006, 03h56
  3. Un edit control en lecture seule mais pas avec un fond gris?
    Par Magus (Dave) dans le forum Windows
    Réponses: 2
    Dernier message: 04/12/2005, 21h58
  4. [Win32] Transparence d'un Edit Control
    Par bigbang dans le forum MFC
    Réponses: 20
    Dernier message: 04/02/2005, 08h22
  5. [mfc]edit control
    Par marseillais57 dans le forum MFC
    Réponses: 4
    Dernier message: 21/06/2004, 10h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo