0
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
int main()
{
    char  ch[20];
    int i,j;

     do{
        printf("Donner ch :");
        scanf("%s",&ch);
    }while(strlen(ch)<0);


    for(i=0;i<strlen (ch);++i)
    {
        if(ch[i] == 'e')
        {
            for(j=i;j<=strlen(ch)-1;j++)
                ch[j]=ch[j+1];


        }
    }

     printf("la chaine obtenue est %s", ch);
    return 0;
}

compilation result

Here doesnt run sucessfully enter image description here

Here it runs sucessfully enter image description here

  • 1
    You should enable your compiler warnings, the `scanf` call is wrong. – alex01011 Dec 19 '22 at 16:49
  • What words contain spaces? If you want to read lines, `fgets` would be simpler – Ted Lyngmo Dec 19 '22 at 16:49
  • Does this answer your question? [How do you allow spaces to be entered using scanf?](https://stackoverflow.com/questions/1247989/how-do-you-allow-spaces-to-be-entered-using-scanf) – alex01011 Dec 19 '22 at 16:51
  • What @alex means is that ```scanf``` requires a pointer as it's second argument, but as the name of the array ```ch``` is a pointer to the first element of the array, the ```&``` operator is not required here. Or in other words, ```scanf``` expected a ```char *```, but you passed it a ```char **```. – Harith Dec 19 '22 at 16:51
  • i mean close like: help me – Mohamed Bouattour Dec 19 '22 at 16:53
  • 2
    @Haris To be precise, he passed a pointer to an array of `char[20]`;) – alex01011 Dec 19 '22 at 16:58
  • it doesnt answer my question thx for your support @alex01011 – Mohamed Bouattour Dec 19 '22 at 16:58
  • ```scanf``` ignores everything to the right side of a whitespace character. If you wish to read a whole line, consider using ```fgets``` instead. – Harith Dec 19 '22 at 16:59
  • 3
    @alex01011 Even though the type error is really bad formally it has exactly zero consequences in real life ;-). An address is an address is an address. – Peter - Reinstate Monica Dec 19 '22 at 17:00
  • 2
    @MohamedBouattour I'm pretty sure it does answer your question. If you insist on using `scanf` you can do so by using `scanf("%19[^\n]", ch)` – alex01011 Dec 19 '22 at 17:01
  • 2
    Your... wording... is already pointing to an error. What we call a "word" usually doesn't have spaces. In fact, "word is defined by the *absence* of spaces ;-). Therefore, a "word that contains spaces" is an oxymoron, even an antinomy. So you *actually* want to do something else, namely work on text chunks that are delimited in a different way than by whitespace. That delimiter can be a newline which makes your chunk of input a *line* (but only coincidentally, because of how a terminal works), or the contents of an XML attribute, or a Jason value... – Peter - Reinstate Monica Dec 19 '22 at 17:04
  • thx alot @alex01011 i puted 23 rather than 19 the program runs sucessfully – Mohamed Bouattour Dec 19 '22 at 17:10

0 Answers0