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

  • Home
  • SEARCH
  • 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 4337180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:54:31+00:00 2026-05-21T10:54:31+00:00

Hey there! I’m stuck on an ANSI C problem which I think should be

  • 0

Hey there!
I’m stuck on an ANSI C problem which I think should be pretty trivial (it is at least in any modern language :/).

The (temporary) goal of my script is to split a string (array of char) of 6 characters (“123:45”) which represents a timestamp minutes:seconds (for audio files so it’s ok to have 120 minutes) into just the minutes and just the seconds.

I tried several approaches – a general one with looking for the “:” and a hardcoded one just splitting the string by indices but none seem to work.

void _splitstr ( char *instr, int index, char *outstr ) {
char temp[3]; 
int i; 
int strl = strlen ( instr );
if ( index == 0 ) {
    for ( i = 0; i < 3; ++i ) {
        if ( temp[i] != '\0' ) {
            temp[i] = instr[i];
        }
    }
} else if ( index == 1 ) {
    for ( i = 6; i > 3; i-- ) {
            temp[i] = instr[i];
        }
    }
strcpy ( outstr, temp );
}

Another “funny” thing is that the string length of an char[3] is 6 or 9 and never actually 3. What’s wrong with that?

  • 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-05-21T10:54:32+00:00Added an answer on May 21, 2026 at 10:54 am

    How about using sscanf(). As simple as it can get.

        char time[] = "123:45";
        int minutes, seconds;
    
        sscanf(time, "%d:%d", &minutes, &seconds);
    

    This works best if you can be sure that time string syntax is always valid. Otherwise you must add check for that. On success, sscanf function returns the number of items succesfully read so it’s pretty easy to detect errors too.

    Working example: http://ideone.com/vVoBI

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I was wondering if there were any way to upload images in ASP?
Hey, is there any built in functions or something like that in php that
Hey there, I've got a block of HTML that I'm going to be using
Hey, in the Programming Pearls book, there is a source code for setting, clearing
Hey there, everyone. A really random question, but I'm looking to get into some
Hey there, I'm a first time stackoverflow poster, long time reader. I'm dipping the
Hey there. My app is going to be using an array of 64 ImageButtons
Hey there, it's been a week with Django back here so don't mind me
Hey there! now first of all some might want to shout that there are
Hey there, I am fresh to iPhone development and Objective C. Sorry if this

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.