2011-02-03 13:47:29 +01:00
|
|
|
#include <stdio.h>
|
2011-03-07 17:36:41 +01:00
|
|
|
#include <string.h>
|
2011-02-03 13:47:29 +01:00
|
|
|
|
|
|
|
int lirechl(char *s, int n);
|
2011-03-07 17:36:41 +01:00
|
|
|
void squeeze( char *s , char *t, char c);
|
2011-02-03 13:47:29 +01:00
|
|
|
|
|
|
|
int lirechl(char *s, int n)
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
i=0;
|
|
|
|
while( i < n && ( c = getchar() ) != '\n' )
|
|
|
|
s[i++] = c ;
|
|
|
|
|
|
|
|
s[i] = '\0';
|
|
|
|
|
|
|
|
if ( c != '\n' )
|
|
|
|
while ( getchar() != '\n' );
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
char string[10];
|
2011-03-07 17:36:41 +01:00
|
|
|
printf("Écrivez puis appuyez sur 'Entrée' : ");
|
|
|
|
int nb = lirechl(&string[0], 7);
|
|
|
|
printf("Nombre de caracteres jusqu'à saut de ligne : %d \n",nb);
|
2011-02-03 13:47:29 +01:00
|
|
|
}
|
2011-03-07 17:36:41 +01:00
|
|
|
|
|
|
|
// This is for another exercise.
|
2011-02-03 13:47:29 +01:00
|
|
|
void squeeze( char *s , char *t, char c)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int k = 0;
|
|
|
|
while( s[i] != '\n' && s[i] != '\0' )
|
|
|
|
{
|
|
|
|
if (s[i] != c && k < strlen(t))
|
|
|
|
{
|
|
|
|
t[k] = s[i];
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
t[k]='\0';
|
|
|
|
}
|