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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:24:30+00:00 2026-05-13T10:24:30+00:00

This is my version of detab, from this K&R exercise: Modify detab to accept

  • 0

This is my version of detab, from this K&R exercise:

Modify detab to accept a list of tab stops as arguments. Use the default tab setting if there are no arguments.

#include <stdio.h>
#include <stdlib.h>
#define TAB_STOP 8

/* replaces tabs from input with the proper amount of blank spots */
int Detab()
{
     int c, x;
     int column;
     x = column = 0;

     while((c=getchar())!=EOF)
     {
        if(c == '\n') /* reseting counter if newline */
        {
            putchar(c);
            return 1;
        }
        else if(c!='\t')  /* column counts places to tab spot */
        { 
             putchar(c);
             column++; 

             if(column == TAB_STOP) 
             column = 0;
        }
        else /* tab */
        {
           for(x=0; x<TAB_STOP - column; x++)
           putchar('_');

           column = 0;
        } 
     }
     return 0;
}
int main(int argc, char *argv[])
{
     int valid;

     while((valid=Detab())!=0);

     printf("Press any key to continue.\n");
     getchar();
     return 0;
}

My question is if there are more then one argument—for example 5, 8, 10—when is the next tab stop suppose to start being active? At which point should program start using TAB_STOP 8 instead of the starting 5? After a newline or how should I do this?

I’m also not really sure if I should put all of this into main, or should I stick with a separate function?

Edit: ok this is what i tried.

#define MAX_ARGUMENTS 100
int main(int argc, char *argv[])
{
     int i, val = 0;
     int nums[MAX_ARGUMENTS];
     int x = 0;

     for(i = 1; i < argc; i++) {

           while(isdigit(*argv[i])) {
             val = val * 10 + *argv[i] - '0';
             *++argv[i];
           }

           nums[x++] = val;
           val = 0;

     }

     Detab(nums);       


     printf("Press any key to continue.\n");
     getchar();
     return 0;
}

Am i on the right track? Can this work? I still havent modified detab.

  • 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-13T10:24:30+00:00Added an answer on May 13, 2026 at 10:24 am

    I’d interpret TABSTOP 5 8 10 to mean there are tab stops at the 5th, 8th, and 10th columns (and after that, every 8 columns, or whatever you’re using as the default. It’s open to question whether the next tab stop after column 10 should be at column 18 (8 spaces later) or 16 (the next multiple of the default 8).

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

Sidebar

Ask A Question

Stats

  • Questions 260k
  • Answers 260k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Depending on your settings, the auto saved file likely exists… May 13, 2026 at 11:23 am
  • Editorial Team
    Editorial Team added an answer Is you os vista or win 7?, if so then… May 13, 2026 at 11:23 am
  • Editorial Team
    Editorial Team added an answer Ended using SetTimer : http://msdn.microsoft.com/en-us/library/ms644906%28VS.85%29.aspx Thanks! May 13, 2026 at 11:23 am

Related Questions

Ok, so here's the full description of the problem I'm having: I am trying
The Problem I'm working on a problem that involves sharding. As part of the
I was working through the Programming in Scala book, and was struck by a
The will_paginate gem is broken on my version of Oracle. The default paginate_by_sql method
I just released a free version of a paid app store application, and I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.