Having char double[] = "1.2345678"; , I have to trim all digits in 4nd place and above after the . in this char * i.e make it to "1.234" .
Having char double[] = 1.2345678; , I have to trim all digits in 4nd
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One obvious solution is to replace a character by
NUL, like so:Note that the exact position might differ, depening on how many digits appear before the ‘.’ character.
Iterate over the string
foo, change the state inpassed_dotif you come across ‘.’, and insert aNULafter 4 more characters:If you can’t afford to buy more RAM, you may
strdup()the resulting string andfree()the old one in order to save memory: