#include <stdio.h> int main(void) { char test2[10] = {0}; scanf("%s", test2); printf("%s\n", test2); scanf("%s", &test2); // Provoque tout de même un petit warning printf("%s\n", test2); return 0; }
#include <stdio.h> int main(void) { char* a = NULL; char b[1] = {42}; a = malloc(sizeof(char) * 1); printf("a: %p %p %p\n", a, &a, &a[0]); printf("b: %p %p %p\n", b, &b, &b[0]); free(a); return 0; }
a: 0x2104010 0x7fff0cbcfa08 0x2104010
b: 0x7fff0cbcfa07 0x7fff0cbcfa07 0x7fff0cbcfa07
#include <stdio.h> #include <string.h> #include <stdlib.h> void EcrieToto(char** stValeur); void EcrieToto(char** stValeur) { char* test; test = *stValeur; strcpy(test,"toto"); } int main(int argc, char* argv[]) { char* test1; char test2[10]; test1=(char*)malloc(sizeof(char)*10); EcrieToto(&test1); printf("%s\n",test1); free(test1); EcrieToto((char**)&test2); printf("%s\n",test2); return 0; }
Unhandled exception at 0x1026f689 (msvcr90d.dll) in testVincent.exe: 0xC0000005: Access violation writing location 0xcccccccc.
#include <stdio.h> #include <string.h> #include <stdlib.h> void ecrieToto(char* stValeur) { strcpy(stValeur, "toto"); } int main(void) { char* test1 = NULL; char test2[10]; test1 = malloc(sizeof(char) * 10); ecrieToto(test1); printf("%s\n", test1); free(test1); ecrieToto(test2); printf("%s\n", test2); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionforcément c'est un test
ET JE SUIS PAS UN GORET, SI JE FAIT SA C'EST QUE J'AI MES RAISONS
Bà si, dans 95% des cas on peut compiler du C en C++ je viens d'ailleurs de faire évoluer un projet dans ce sens (ou donne moi un exemple pck moi j'en trouve pas).
#include <stdio.h> #include <string.h> #include <stdlib.h> void EcrieToto(char** stValeur); void EcrieToto(char** stValeur) { strcpy(*stValeur,"toto"); } int main(int argc, char* argv[]) { char* test1; char test2[10]; test1 = test2; EcrieToto(&test1); printf("%s\n",test2); return 0; }
restrict en C Tiens connais pas (c'est pas pour les collections sa ???)
Enfin bref aller cette fois bon week end (Starcraft II m'attend )