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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:21:25+00:00 2026-05-31T05:21:25+00:00

So i have this big code ( so wont be able to put the

  • 0

So i have this big code ( so wont be able to put the entire thing here).
But at a point i have this.

while(ptr1!=NULL)
{
printf("%sab ",ptr1->name);
puts(ptr1->name);
ptr1=ptr1->next;
}

Now my ptr1 point to a an entry of the array of a structure( each entry being a linked list), and the structure was populated from a file.

Now in this loop it prints

FIRSTab FIRST
SECONDab SECOND
THIRD

Now why doesnt my THIRD GETS PRINTED TWICE?

Also if i do

printf(" %s",ptr1->name); // i.e. one space before %s

I get

THIRDD

Putting 2 spaces before %s gives me

THIRDRD

3 spaces gives

THIRDIRD

And so on.

Also if i try to do strcmp(ptr1->name,”THIRD”) i wont get the correct comparison for THIRD.
Why??

Here is how i populated my structure.

// G is the structure, fp is passed as argument to function.
//THe file format is like this.
//FIRST SECOND THIRD
//NINE ELEVEN 
//FOUR FIVE SIX SEVEN
// and so on.
int i=0,j=0,k=0;
char string[100];
while(!feof(fp))
{
if(fgets(string,100,fp))
{
G[i].index=i;
k=0;j=0;
//\\printf("%d",i);
//puts(string);
node *new=(node*)malloc(sizeof(node));
new->next=NULL;
G[i].ptr=new;
node* pointer;
pointer=G[i].ptr;
while(string[j]!='\n')
{
    if(string[j]==' ')
    {
    pointer->name[k]='\0';

    k=0;
        node *new=(node*)malloc(sizeof(node));
        new->next=NULL;
        pointer->next=new;
        pointer=pointer->next;
        j++;
    }
    else
    {   
    pointer->name[k++]=string[j]; 
    j++; 
    }
}
pointer->name[k]='\0';
i++;
}
  • 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-31T05:21:25+00:00Added an answer on May 31, 2026 at 5:21 am

    Your third string probably contains the characters THIRD followed by \r (carriage return). Why it contains this can only be determined by knowing the contents of the file and how your read it.

    It is likely that you are either working on a system that uses a single newline character as a line terminator (but the file you are opening comes from a system that uses a carriage return and newline pair) or that the file pointer that you were passed (fp) was opened in binary mode.

    If you can’t change the file pointer to be opened in text mode then a quick fix might be to change this condition while(string[j]!='\n') to while(string[j]!='\n' && string[j] != '\r'), although you might want a more robust solution that handles multiple whitespace characters.

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

Sidebar

Related Questions

I have quite a big code here... But fortunately it is not needed to
I have this big doubt. When ever i use base64Binary in an .xsd schema
so I have this HTML table with a bunch of big numbers in it
I have a script that loads big images into the body in this fashion
I have a var that contains a big list of words (millions) in this
I have a report with a big title, so this report will have 2
I have been trying to serialize a pretty big object. This object uses dictionaries
This is a C# problem. I have a big object in memory at a
I have a JS script with tons of functions, on big on is this:
I have encountered this problem a few times, and am not able to figure

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.