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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:06:26+00:00 2026-06-03T21:06:26+00:00

I’ve wrote a program that gets from the user a number, and then gets

  • 0

I’ve wrote a program that gets from the user a number, and then gets from the user a name for every number…
for example if the user entered the number 10, it’d take 10 names and put it in an array of structs…
Everything is working great, except that when I print the names, it skip’d the first letter…
like if I put in the name “Amit”, it printed “mit”… , also, the last string I’ve entered didnt save at all..
Here is what I wrote :

const number_candidates; // Getting the number of candidates
#define MAX 256
#define min_candidate 10
#define max_candidate 60000

typedef struct candidate // Getting details for each candidate
{
    char name[MAX];
    int sing_grade;
    int per_grade;
    int cam_grade;
    int sharmanti_grade;
}candidate;

void get_details_candidates(candidate candidate[MAX])
{
 int i = 0;
 printf ("\n");
 for (i = 0 ; i < number_candidates ; i++)
 {
     printf ("Please enter the %d name: ", i + 1);
     fgets (candidate[i].name, MAX, stdin);
     getchar();
 }
}

Here is the printing:

    for (i = 0 ; i < number_candidates ; i++)     
{
    printf ("%s\n", candidates[i].name);
}

Thanks for your help!

  • 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-03T21:06:28+00:00Added an answer on June 3, 2026 at 9:06 pm

    The getchar() after the fgets() is eating the first letter of the following line.

    Your problem reading the first name may be caused by a stray newline in the input stream. To flush stdin before your input loop you can use something like this:

    while((c = getchar()) != '\n' && c != EOF)
    /* discard the character */;
    

    I think fflush(stdin) is undefined behaviour so don’t do that.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a
I need to clean up various Word 'smart' characters in user input, including but

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.