Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:18:06+00:00 2026-06-05T15:18:06+00:00

I got a string, that inside it has: 2@0.88315@1@1.5005@true@0.112 and it keep going… I

  • 0

I got a string, that inside it has:

2@0.88315@1@1.5005@true@0.112 and it keep going…

I need to switch every number thats 2 or bigger, to 1,
so I wrote this :

for (i = 0 ; i < strlen(data) ; i++)
{
    if (data[i] >= 50 && data[i] <= 57) // If it's a number
    {
        data[i] = '1'; // switch it to one
        while (data[i] >= 48 && data[i] <= 57)
        {
           i++;
        }
     }
 }

The problem is, that it makes numbers like 0.051511 as 1.111111 too…
Because it doesnt look at a double as one number, but every number seperatly…
How can I do it ?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:18:10+00:00Added an answer on June 5, 2026 at 3:18 pm

    To clarify the question since it is unclear, you want to have the following input:

    "2@0.88315@1@1.5005@true@0.112"
    

    To be modified to be the following:

    "1@0.88315@1@1@true@0.112"
    

    Your problem is that you need to parse each number into a float value to do any sort of comparison. Either this, or you will need to manually parse it by checking for a ‘.’ character. Doing it manually is rigid, error-prone and unnecessary because the C standard library provides functions which can help you.

    Since this is homework, I’ll give you some tips on how to approach this problem instead of the actual solution. What you should do is try to write a solution with these steps and if you get stuck, edit the original question with the code you wrote, where it is failing and why you think it is failing.

    Your first step is to tokenise the input into the following:

    "2"
    "0.88315"
    "1"
    "1.5005"
    "true"
    "0.112"
    

    This can be done by iterating through the string and either splitting it or using the pointer after which a ‘@’ character occurs. Splitting the string can be done with strtok. However, strtok will split the string by modifying it which is not necessarily needed in our case. The simpler method is simply to iterate through the string and stop each time after a ‘@’ character is reached. The input would then be tokenised to the following:

    "2@0.88315@1@1.5005@true@0.112"
    "0.88315@1@1.5005@true@0.112"
    "1@1.5005@true@0.112"
    "1.5005@true@0.112"
    "true@0.112"
    "0.112"
    

    Some of these substrings do not start with a string which represents a float. You will need to determine which of them do. To do this, you can attempt to parse the front of each string as a float. This can be done with sscanf. After parsing the floats, you will be able to do the comparison you want to.

    You are trying to modify the string into a different length so when replacing a float value by a ‘1’, you need to check the length of the original value. If it is longer than 1 character, you will have to shift the subsequent characters forward. For example:

    "3.423@1"
    

    If you parsed the first token and found it to be > 2, you would replace the first character with a ‘1’. This result in:

    "1.423@1"
    

    You then still need to delete the rest of that token by shifting the rest of the string down to get:

    "1@1"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a variable-width-font NSString that has to fit inside a fixed size UIView.
I got a string that contains the current date by using this : NSString
So I've got a string that looks like 012 + 2 - 01 +
This question got me thinking about bare strings. When PHP sees a string that's
I've got wide string and I'm writing it to a wofstream that I opened
I've got a method that creates a string then appends additional strings onto it:
So I've got a column in a table that contains a string values (keywords
I've got a method in a class that's writing to some string, which calls
I've got a batch of strings that I need to cut down. They're basically
I have a TabHost that has two ViewFlippers, and inside each ViewFlipper are three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.