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 9215095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:07:30+00:00 2026-06-18T02:07:30+00:00

I am 2 month old kid with using C. I have a simple problem

  • 0

I am 2 month old kid with using C. I have a simple problem with passing ip-range as argument to main function and getting an array with indivisual ips.

eg. func-ip-range should take 1.1.1.1-10 as argv and return an array [1.1.1.1, 1.1.1.2, 1.1.1.3 ……… 1.1.1.10].

The way I was approaching this problem is as follows and I could not get the “segmentation fault” debugged as I have no Idea where the code is choking.

Any help would be very much appreciated to save this kid.

Approach is to pass the command line argument to *ip_str and read this string char by char. Once I meet first ‘.’ I increase the count ‘c’ and when count c == 3 i want to store the string from there to a new string variable till I reach ‘-‘ and after reaching ‘-‘ the rest of the string to a new string. But I have serious issue with my exposure to the programme writing and debugging.

The direction on how to reach the problem other than this will be very good for my learning.

    void array_ip(char *ip_str,char **iplist)
    {
    for(i=0,j=0;*(ip_str+i) != '\0';i++)
    {
            if(*(ip_str+i)=='.')
            {c++;
            }
            if(c==3 && (*(ip_str+i )!= '-'))
            {
            *(a+j) = *(ip_str+i);
            j++;
            }
            if(*(ip_str+i) == '-')
            {
            break;
            }
    }
    for(k=0;*(ip_str+i) != '\0';k++,i++)
    {
    *(b+k)=*(ip_str+i);
    }

    printf("the starting last octet is %s \n",a);
    printf("the Ending last octet is %s \n",b);
    }
  • 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-18T02:07:32+00:00Added an answer on June 18, 2026 at 2:07 am

    Why not use the help of ?strrchr()

    Do a man 3 strrchr on your linux if you are using linux

    Edit : Use strtok instead :

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int main()
    {
            char str[] = "1.1.1.1-10";
            char * temp;
    
            temp = strtok(str,"-");
            temp = strtok(NULL,"-");
            int number = atoi(temp);
            printf("%d",number);
    return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to delete files which are more than one month old using c# script.
I'm using Gnat (old compiler of ada95) and I'm having problem to print the
I have made a function in old mysql and now want to transfer it
today I just opened my 1,5 month old project and wanted to add a
Long time listener, first time caller. I'm a 6 month old dev from Code
I can extract the month and day by using Day(Date()) , Month(Date()) . I
function GetDaysInMonth(month, year) { return 32 - new Date(year, month, 32).getDate(); } Ok, I
I have searched for this but did not find a perfect function in php.
So, we have an old VB 6 App written many many years ago. It
I need to move the data that is a month old from a logging

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.