4 Replies - 839 Views - Last Post: 15 August 2015 - 06:54 AM Rate Topic: -----

#1 thanhnhanpham   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-August 15

How to delete a char from a string using stdio.h

Posted 14 August 2015 - 11:05 PM

Hello guys, I have a question and can you please help me solve it, can I able to delete a char from a string using stio.h ?
EX :
[code]
#include <stdio.h>
#include <string.h>
void main()
{
char s[]="Mystring";
int n,i,j;

}
[code]

I need a function call delchr(string,position,number of charactrer need to delete)
delchr(s,2,1) and then s==Mytring
delchr(s,2,3) and then s==Mying
delchr(s,4,2) and then s==Mysting
P/s : that function just like in pascal code , but it doesn't have in C++ :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to delete a char from a string using stdio.h

#2 g4143   User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 52
  • Joined: 30-April 09

Re: How to delete a char from a string using stdio.h

Posted 15 August 2015 - 01:39 AM

Well first main() should return an integer.
Was This Post Helpful? 1
  • +
  • -

#3 g4143   User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 52
  • Joined: 30-April 09

Re: How to delete a char from a string using stdio.h

Posted 15 August 2015 - 01:51 AM

Here's a bare minimum which neglects all error checking and possible screw-ups. It basically assumes the function delchr() is called with reasonable values.

#include <stdio.h>

void delchr(char *str, int start, int num){
    sprintf(&str[start], "%s", &str[start + num]);
}

int main(int argc, char** argv) {
    char s[]="Mystring";
    fputs(s, stdout);
    fputs("\n", stdout);
    delchr(s, 3, 3);
    fputs(s, stdout);
    return 0;
}



Was This Post Helpful? 1
  • +
  • -

#4 thanhnhanpham   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-August 15

Re: How to delete a char from a string using stdio.h

Posted 15 August 2015 - 05:53 AM

thanks you so much but can you please explain more how your code work ? And also what fputs does ? Sorry for that but please help, I'm just a beginner =))
Was This Post Helpful? 0
  • +
  • -

#5 g4143   User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 52
  • Joined: 30-April 09

Re: How to delete a char from a string using stdio.h

Posted 15 August 2015 - 06:54 AM

View Postthanhnhanpham, on 15 August 2015 - 06:53 AM, said:

thanks you so much but can you please explain more how your code work ? And also what fputs does ? Sorry for that but please help, I'm just a beginner =))


You want an explanation for the code I posted and you don't know what fputs does? I'm not sure the forum moderator will give that much space for an explanation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1