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

The Archive Base Latest Questions

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

I am rather new to C and am probably doing something stupid but I

  • 0

I am rather new to C and am probably doing something stupid but I can’t find out why my string array isn’t keeping the previous values while the grade is keeping all the values entered:

for(int i=0; i <noOfStudents; i++)
{
    do{
        printf("Please enter Student Full Name.");
        //read string till enter
        scanf(" %[^\n]", &studentFullName);
        if(studentFullName == "")
        {
            printf("Invalid Student Name!\n\n");
            getchar();
        }
        else
        {
            names[i] = studentFullName;
            validStudentName = 1;
        }
    }while(validStudentName != 1);

    do{
        printf("Please enter Student Grade.");
        scanf_s(" %d", &grade);
        if(grade < -1 && grade >100)
        {
            printf("Invalid Student Grade!\n\n");
            getchar();
        }
        else
        {
            grades[i] = grade;
            validGrade = 1;
        }
    }while(validGrade != 1);

    printf("\n");
}
  • 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-27T05:57:57+00:00Added an answer on May 27, 2026 at 5:57 am

    grade is an integer. When you do:

    int a;
    int b = 3;
    a = b;
    b = 4;
    

    then a continues to be 3, because integers are copied.

    studentFullName is, however, a pointer. Just like integers, pointers are copied. However, the data the pointer points to is not. So, basically, you’ve got your entire names[] array as a bunch of pointers, all pointing to the exact same data.

    There are several functions that will copy the pointed-to data for you, the one you’re looking for is probably strdup. Note that you must free all the pointers you get back from strdup.

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

Sidebar

Related Questions

The solution is probably rather simple, but I just can't figure it out. Here
I am rather new to the Entity Framework, so I am probably overlooking something
Rather new to php, so sorry if this seems stupid. I'm really copying a
I am rather new to Linux device driver programmring, but for debugging purposes, I
Probably a stupid question but I'm still trying to wrap my head around nHibernate.
I have a pointer in GDB, how can I find out where it was
I'm probably just being daft but my Google searches are not working out well.
I know this question is probably straightfoward but I'm new to php and programming...
This is probably a silly question, but I'm pretty new to Java and I
This is probably something simple but I'm scratching my head over easing with the

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.