Comment ça un buffer de TCHAR ?
Comment ça un buffer de TCHAR ?
The computer has the intelligence of anyone who uses it
TCHAR lpstrFile[MAX_PATH] = {0};
De cette manière là ? Puis, quelle est la syntaxe car je n'y arrive pas, ca me m'affiche pas le contenu du txt...
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 #include <windows.h> #include <tchar.h> #include <stdio.h> int main(void) { charger_fichier_texte(); } int charger_fichier_texte() { TCHAR lpstrFile[MAX_PATH] = {0}; FILE *fp = NULL; char n_file[256]; BOOL ret; n_file[0]=0; OPENFILENAME file; memset(&file,0,sizeof(OPENFILENAME)); file.lStructSize=sizeof(OPENFILENAME); file.hwndOwner =NULL; file.lpstrFilter="*.*\0"; file.lpstrCustomFilter = NULL; file.nMaxFile = 256; file.lpstrFile = n_file; file.nFilterIndex = 0; file.lpstrTitle=NULL; file.lpstrFileTitle =NULL; file.nMaxFileTitle=0; file.lpstrInitialDir = NULL; file.lpstrTitle = NULL; file.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST; file.lpstrDefExt = NULL; if (GetOpenFileName(&file)==0) printf("Erreur..."); else printf("%s\n",file.lpstrFile); printf("\n\n"); fp = (FILE *) _tfopen(lpstrFile,_T("r")); if (fp != NULL) { printf("%s",lpstrFile[MAX_PATH]); } system("PAUSE"); }
The computer has the intelligence of anyone who uses it
Essaie plutôt ceci:
Note: je n'ai pas testé, je n'ai pas essayé de compiler car il est tard. Mais c'est l'idée générale...
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 #include <windows.h> #include <tchar.h> #include <stdio.h> #ifndef ARRAYSIZE #define ARRAYSIZE(x) ((sizeof x)/(sizeof x[0])) #endif int charger_fichier_texte(); int main(void) { charger_fichier_texte(); return 0; } int charger_fichier_texte() { TCHAR fileName[MAX_PATH] = {0}; BOOL ret; /* Demande du nom de fichier */ { OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = NULL; ofn.lpstrFilter = _T("*.*\0"); ofn.lpstrCustomFilter = NULL; ofn.nMaxFile = ARRAYSIZE(fileName); ofn.lpstrFile = fileName; ofn.nFilterIndex = 0; ofn.lpstrTitle = NULL; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST; ofn.lpstrDefExt = NULL; ret = GetOpenFileName(&ofn); if (!ret) printf("Erreur..."); else _tprintf(_T("%s\n"), file.lpstrFile); printf("\n\n"); } /* Ouverture du fichier */ if(ret) { FILE *fp = NULL; fp = _tfopen(fileName, _T("r")); if (fp != NULL) { /* Lit la première ligne du fichier et l'affiche */ char line[256]; fgets(line, ARRAYSIZE(line), stdin); printf("%s", line); fclose(fp), fp=NULL; } } system("PAUSE"); }
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.
Merci beaucoup Médinoc, j'ai juste eu a changer dans ces morceaux
_tprintf(_T("%s\n"), file.lpstrFile); >>> file.lpstrFile en ofn.lpstrFile
fgets(line, ARRAYSIZE(line), stdin); >>> stdin en fp
Merci, de plus j'ai compris pourquoi je n'y arrivais pas
The computer has the intelligence of anyone who uses it
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager