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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:57:25+00:00 2026-05-12T15:57:25+00:00

I have read a few lines of text into an array of C-strings. The

  • 0

I have read a few lines of text into an array of C-strings. The lines have an arbitrary number of tab or space-delimited columns, and I am trying to figure out how to remove all the extra whitespace between them. The end goal is to use strtok to break up the columns. This is a good example of the columns:

Cartwright   Wendy    93
Williamson   Mark     81
Thompson     Mark     100
Anderson     John     76
Turner       Dennis   56

How can I eliminate all but one of the spaces or tabs between the columns so the output looks like this?

Cartwright Wendy 93

Alternatively, can I just replace all of the whitespace between the columns with a different character in order to use strtok? Something like this?

Cartwright#Wendy#93

edit: Multiple great answers, but had to pick one. Thanks for the help all.

  • 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-12T15:57:25+00:00Added an answer on May 12, 2026 at 3:57 pm

    If I may voice the “you’re doing it wrong” opinion, why not just eliminate the whitespace while reading? Use fscanf("%s", string); to read a “word” (non whitespace), then read the whitespace. If it’s spaces or tabs, keep reading into one “line” of data. If it’s a newline, start a new entry. It’s probably easiest in C to get the data into a format you can work with as soon as possible, rather than trying to do heavy-duty text manipulation.

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

Sidebar

Related Questions

I'm trying to read the contents of a text file into the attributes of
I have read few articles about table partioning but still I am bit confused
Although I have read a few previously answered questions regarding a similar issue, I
I need to create an excel file via C#. I have read a few
I'm fairly new to working with relational databases, but have read a few books
I have read quite a few selcet+update questions in here but cannot understand how
I've read a few posts on this but I'm still confused. I have this
I have read various posts in stackoverflow and I am trying to figure out
I know there are quite a few text-to-array questions out there, but I am
I am trying to make a disorganized text file into a list suitable for

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.