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

Related Questions

Currently, I have this version of the autocomplete control working when returning XML from
I have a Model called Version that looks like this: from google.appengine.ext import db
How to find items in Outlook inbox by from email? This version works and
Ok. This version of select works: $select = $this->select(); $select->setIntegrityCheck(false); $select->from(array('u' => $this->_name), array('u.id',
I'm trying to use lucene 4.0 snapshot version, however StandardAnalyzer is missing in this
Griffon JMX Plugin 0.3 don't work. anyone use this version 1.got error: no lib
I am using JBoss-6.0.0 AS which by default comes with HornetQ-2.1.2 version but this
We are converting our application from using Sql Server Express (let's call this version
I've built MinGW from trunk-version GCC-4.7.0: http://code.google.com/p/mingw-builds/downloads/list In the description of changes of this
I am creating a report with IReports version 3.7.5 (currently we use this version).

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.