0

some help, I want to delete a Specific character from a string, for example if I put 5 then the program delete char number 5

Delete a char from string.

24th Dec 2021, 10:43 AM
Elmahdi AIT ITTO
9 Respuestas
+ 3
You attempt in the playground works. Line 11 has to have %ld instead of %d because strlen returns a size_t type of variable. For learning you are doing well. Later after you have learned more C, the scanf in line 13 can be dangerous in your code. Keep up the good work, you are showing progress.
24th Dec 2021, 2:01 PM
William Owens
William Owens - avatar
+ 2
// this will help you. Next time link also your attempt #include <stdio.h> int main() { char string[] = "the beautiful things in life are for free."; printf("first character: %c\n", string[0]); printf("fifth character: %c\n", *(string+4)); printf("last character: %c\n", string[40]); string[0] = 'T'; printf("\n%s\n", string); return 0; }
24th Dec 2021, 11:07 AM
JaScript
JaScript - avatar
+ 1
Thanks all of you.
24th Dec 2021, 5:29 PM
Elmahdi AIT ITTO
0
//thanks for replying, here is my attempt #include <stdio.h> #include <string.h> int main() { char str[100]; int i, pos; printf ("put your string :\n"); gets(str); printf("put the position of char you want to delete :\n"); pos = getchar(); for(i=pos; i<strlen(str); i++) str[i]=str[i+1]; printf("your string after edit :\n %s", str); return 0; }
24th Dec 2021, 11:30 AM
Elmahdi AIT ITTO
0
but it doesn't work
24th Dec 2021, 11:30 AM
Elmahdi AIT ITTO
24th Dec 2021, 12:15 PM
Elmahdi AIT ITTO