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.
9 Réponses
+ 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.
+ 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;
}
+ 1
Thanks all of you.
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;
}
0
but it doesn't work
0
my new attempt,
https://code.sololearn.com/c38FG0jn6zmn/?ref=app