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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:40:16+00:00 2026-06-08T05:40:16+00:00

I have a text file which contains lines, such that every line contains no

  • 0

I have a text file which contains lines, such that every line contains no more than 80 chars. every line contains (one or more words) divided by commas or spaces. I need lexicography sort the words. I want to use scanf with the symbol “%s” of strings, but it considers only spaces. So I guess I can’t. any smarter way to deal with the parsing the words than get char by char?

Here’s a sketch of what I was planning to do:

   char**arr;
    arr=calloc(Size, sizeof(char)*80);
    int m=0;

    while (!feof(file)) {

        char c=fgetc(file);
        while (c!='/n') {
             j=0;
            char* current;
            current=calloc(1,sizeof(char)*80);
            while (c!=','&& c!=' ' && c!='/n') {
                current[j]=c;
                j++;
                c=fgetc(c);
            }
            current[j]='\0';
            arr[m]=current;

            free(current);

        }
    }
  • 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-08T05:40:17+00:00Added an answer on June 8, 2026 at 5:40 am

    Assuming you have an entire line in a suitable variable (line, below), you could use something like:

    const char *ptr = line;
    char token[80];
    
    while(*ptr != '\0' && sscanf(ptr, "%79[^, ]", token) == 1)
    {
      ptr += strlen(token);
      while(*ptr == ',' || *ptr == ' ')
        ++ptr;
    }
    

    This uses the (rather under-utilized, in my opinion) character group format %[] to grab characters until a comma or space is found, then skip past the parsed token, and any separators that follow.

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

Sidebar

Related Questions

I have a simple text dictionary file, which contains words, separated by ';'.My problem
I have a text file which contains a time stamp on each line. My
If I have a file name myownfile.txt which contains 3 lines of text. foo
I have a text file which contains only lines with a message like: Hello
I have a text file which contains several hundred lines e.g. test.bin:8948549854958 They are
I have a text file which contains some lines as the following: ASDASD2W 3ASGDD12
Hi I have a text file which contains some numerical data. Of that text
I have text file which contains lines as mentioned below <property>PASSWORD_X_1</property> <property>PASSWORD_A_2</property> <property>PASSWORD_B_6</property> so
I have a text file which contains data seperated by '|'. I need to
I have a text file which contains something like this: Hello, my name is

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.