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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:00:27+00:00 2026-05-27T00:00:27+00:00

I have used strtok to tokenize my input file and I need a linked

  • 0

I have used strtok to tokenize my input file and I need a linked list based on the output I got in the follwing format.

String:value-Next --> String:value-Next

I have the strings and values after I tokenized my file.

Here is my code:

FILE *pfi;
main(int argc, char* argv[])
{
    char string[1000], delim[] = " \n";
char *p;
    if(argc<2)
         {
          printf("entering format is wrong. compile program using gcc digraph.c and then enter it as ./a.out input.txt");
         }
    else if(argc == 2)
        {
         pfi=fopen(argv[1],"r");
        }
    if(!pfi)
         return 1;
while(fgets( string, sizeof(string)-1, pfi) != NULL)
     {
          p = string;
      p = strtok( string, delim );      

      while( p != NULL )
          {

               if (sscanf(p, "( %s  ",p)) printf("(\n"); 
            printf("%s\n", p);                    

           p = strtok( NULL, delim );                 
              }

         } fclose(pfi);


return 0;
}

The input file is in format:

A 20
B 30
C 40

Output is:

A
20
B
30
C
40

Please help me to create a linked list of format String:value-Next --> String:value-Next.

  • 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-27T00:00:27+00:00Added an answer on May 27, 2026 at 12:00 am
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    /* Create a struct to hold our data in the link list */
    typedef struct node
    {
       char value[100];
       int ivalue;
       struct node *next;
    } Node_t;
    
    void insertInList(Node_t **root, const char *value, int ivalue);
    void printList(const Node_t *root);
    
    int main(int argc, char *argv[])
    {
       /* head of link list */
       Node_t *root=0;
    
       /* ignore this it is C++ - but its quicker to write an input method for it */
       bool done=false;
       while(!done)
       {
          /* ignore from here */
          std::string value;
          int ivalue=0;
          std::cout << "Enter value: " << std::flush;
          std::cin >> value;
          if(value.size() && value[0]=='q')
          {
             done=true;
             continue;
          }
          std::cout << "Enter ivalue: " << std::flush;
          std::cin >> ivalue;
          /* to here */
          insertInList(&root, value.c_str(), ivalue);
       }
    
       printList(root);
       /* Dont forget to free all the link list members after */
    
       return 0;
    }
    
    /* note head of list is passed as a pointer to a pointer so we can modify it */
    void insertInList(Node_t **root, const char *value, int ivalue)
    {
       Node_t *new_node=*root;
       Node_t *last_node=0;
    
       /* find the end of the list to insert to */
       while(new_node)
       {
          last_node=new_node;
          new_node=new_node->next;
       }
    
       /* reserve memory for new node */
       new_node=(Node_t *)malloc(sizeof(Node_t));
       /* copy data over */
       strncpy(new_node->value, value, sizeof(new_node->value)-1);
       new_node->ivalue=ivalue;
       new_node->next=0;
       if(last_node)
       {
          /* set previous node in list to point to our new node */
          last_node->next=new_node;
       }
       else
       {
          /* corner case for first element in list */
          *root=new_node;
       }
    }
    
    void printList(const Node_t *root)
    {
       const Node_t *node=root;
    
       while(node)
       {
          printf("%s %d\n", node->value, node->ivalue);
          node=node->next;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used split function to split the string in javascript. which is as,
I have used microsoft system.security.cryptography to make md5 in c# application but I need
We have used Custom List View inside that one Text View and two Edit
I have used date picker in my iPad App but the output of date
i have a file containing list paths and other related information of all the
I have used JD decompiler for decompiling a jar file. Affter do that I
I have used Android phonegap application for creating dynamic list with label and corresponding
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have used the XML Parser before, and even though it worked OK, I

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.