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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:02:03+00:00 2026-05-22T01:02:03+00:00

I have this struct typedef struct grade { char firstName[SIZE]; char lastName[SIZE]; int stuNum;

  • 0

I have this struct

typedef struct grade
{
    char firstName[SIZE];
    char lastName[SIZE];
    int stuNum;
}GRADE;

and this output code:

void printData(GRADE grade[], int used)
{
    int i;
    for(i=0; i<used-1; i++)
    {
        printf("%s %s %d\n", grade[i].firstName, grade[i].lastName, grade[i].stuNum);
    }
}

When I attempt to print the char’s they only print the first character of the string, I’m at a stand still and cannot really figure out how to make it print the rest of the string.

This code reads the data file (which is in the format of "Firstname Lastname StudentNumber" in about 17 lines, for example "Mark Markinson 1234" newline "blah blah 1234" etc).

void readData(FILE *infile, GRADE grade[], int *count)
{
    char buf[SIZE] = {0};
    int position=*count;
    int used = 0;
    while( fgets(buf, SIZE, infile))
    { 
        removeNL(buf);

        grade[position].firstName[0] = parseName(buf, &used);
        used++;

        grade[position].lastName[0] = parseName(buf, &used);
        used++;

        grade[position].stuNum = parseNumber(buf, &used);
        used = 0;
        position++;
    }
    *count = position;

}

This is the code that parses the buffer for names:

char parseName(char *str, int *place)
{
    char buf[SIZE] = {0}, name;
    int i=*place,j=0;

    while( str[i] != '\0' && !isspace(str[i]))
    {
        buf[j++] = str[i++];

    }
    buf[j] = '\0';

    *place = i;

    return *buf;
}

after taking some suggestions here i changed some of the code, but it still does the same thing (only first character is printed)

used this way to call the function

parseName(buf, &used, grade[position].firstName);

and parseName is now

void parseName(char *str, int *place, char *firstName)
{
    char buf[SIZE] = {0}, name;
    int i=*place,j=0;    
    while( str[i] != '\0' && !isspace(str[i]))
    {
        buf[j++] = str[i++];

    }
    buf[j] = '\0';

    *place = i;

    *firstName = *buf;
}
  • 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-22T01:02:03+00:00Added an answer on May 22, 2026 at 1:02 am

    The problem is here:

    void readData(FILE *infile, GRADE grade[], int *count)
    {
        char buf[SIZE] = {0};
        int position=*count;
        int used = 0;
        while( fgets(buf, SIZE, infile))
        { 
            removeNL(buf);
    
            grade[position].firstName[0] = parseName(buf, &used);
            used++;
    
            grade[position].lastName[0] = parseName(buf, &used);
            used++;
    
            grade[position].stuNum = parseNumber(buf, &used);
            used = 0;
            position++;
        }
        *count = position;
    
    }
    

    When you call parseName, you just set the first characters. You should pass your array (where you will write the string) to parseName:

    void readData(FILE *infile, GRADE grade[], int *count)
    {
        char buf[SIZE] = {0};
        int position=*count;
        int used = 0;
        while( fgets(buf, SIZE, infile))
        { 
            removeNL(buf);
    
            parseName(buf, &used, grade[position].firstName);
            used++;
    
            parseName(buf, &used, grade[position].lastName);
            used++;
    
            grade[position].stuNum = parseNumber(buf, &used);
            used = 0;
            position++;
        }
        *count = position;
    
    }
    

    Don’t forget to change parseName adding a parameter and writing the result to it.

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

Sidebar

Related Questions

I have this complicated structure thingie: #include <stdlib.h> typedef struct { int x; int
So I have this struct composed of three NSPoint structures. typedef struct AOTriangle_ {
I have this structure which I want to write to a file: typedef struct
Suppose I have this: void func(WCHAR* pythonStatement) { // Do something with pythonStatement }
I have this comparator function for my qsort in C, but I seem to
typedef struct _lnode{ struct _lnode *next; unsigned short row; unsigned short column; short data;
I have this homework to school - I completed it sent it and got
I have a c++ class which exposes collections by providing functions returning ranges, using
I'm working on a 32-bit machine, so I suppose that the memory alignment should

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.