Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1698 connectés 

 


Dernière réponse
Sujet : [C - Linux] problème avec scanf
[SDF]Poire Gets
Syntax
 
#include <stdio.h>
char *gets(char *s);
 
Description
 
Gets a string from stdin.
gets collects a string of characters terminated by a new line from the standard input stream stdin and puts it into s. The new line is replaced by a null character (\0) in s.
gets allows input strings to contain certain whitespace characters (spaces, tabs). gets returns when it encounters a new line; everything up to the new line is copied into s.
The gets function is not length-terminated. If the input string is sufficiently large, data can be overwritten and corrupted. The fgets function provides better control of input strings.
 
Note: For Win32s or Win32 GUI applications, stdin must be redirected.
 
Return Value
 
On success, gets returns the string argument s.
On end-of-file or error, it returns NULL
 
Borland C++ 5.0 Programmer's Guide

Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
[SDF]Poire Gets
Syntax
 
#include <stdio.h>
char *gets(char *s);
 
Description
 
Gets a string from stdin.
gets collects a string of characters terminated by a new line from the standard input stream stdin and puts it into s. The new line is replaced by a null character (\0) in s.
gets allows input strings to contain certain whitespace characters (spaces, tabs). gets returns when it encounters a new line; everything up to the new line is copied into s.
The gets function is not length-terminated. If the input string is sufficiently large, data can be overwritten and corrupted. The fgets function provides better control of input strings.
 
Note: For Win32s or Win32 GUI applications, stdin must be redirected.
 
Return Value
 
On success, gets returns the string argument s.
On end-of-file or error, it returns NULL
 
Borland C++ 5.0 Programmer's Guide
LetoII C'est pour ça qu'il y a une fonction qui prend toute la ligne et remplace \n par \0 et qui doit être gets si mes souvenirs sont bons
Tetedeiench Mon conseil : oublie pas le \n a la fin du printf ( printf("%s\n",chaine) ) pour passer a la ligne et mieux voir ce que tu as écrit.
 
Et ils ont raison, tous la, le scanf s'arrete au premier espace rencontré, et autres aussi ( \0, \n, etc).
LeSchmolluck C'est très simple le scanf s'arrete au PREMIER  
caractère séparateur rencontré :
genre '\0',' ' (l'espace), tabulation,...
 
ta variable reçoit la chaîne jusqu'au premier ' '
donc  '12345ABCD ABC AB ABCD\0'
donne '12345ABCD\0'(dans la variable)
 
('\0' == le retour chariot, RETURN quoi...)
Dj_Jim

nikewlas a écrit a écrit :

Bonjour,
 
je comprends pas pourquoi quand je fais:
 
scanf("%s",chaine);
printf("%s",chaine);
 
et que la chaîne saisie est "totototo to to to to" le programme m' affiche
 
totototo
 
Comment faire pour éviter çà ??
Merci.  




kelle est la declaration de chaine sil te plait????

Gounok Essaie gets, par contre je l'utilise jamais donc regarde dans la doc ;)
nikewlas Bonjour,
 
je comprends pas pourquoi quand je fais:
 
scanf("%s",chaine);
printf("%s",chaine);
 
et que la chaîne saisie est "totototo to to to to" le programme m' affiche
 
totototo
 
Comment faire pour éviter çà ??
Merci.

Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)