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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:50:11+00:00 2026-05-14T01:50:11+00:00

I’m writing a C program but I keep having problems with my array of

  • 0

I’m writing a C program but I keep having problems with my array of chars. I keep getting garbage when I print it using prinf. here is an example of what I get when I print it:

char at t.symbol is Aôÿ¿
char at tabl[0].symbol is A
char at tabl[1].symbol is a
char at tabl[2].symbol is a
char at tabl[3].symbol is d
char at tabl[4].symbol is e
char at tabl[5].symbol is f
char at tabl[6].symbol is g
char at tabl[7].symbol is h
char at tabl[8].symbol is i
char at tabl[9].symbol is x
char at t[0].symbol is a0AÃ
char at t[1].symbol is b)@Ã4
char at t[2].symbol is ckU*
char at t[3].symbol is Aôÿ¿
char at t[4].symbol is gØ

could someone tell me how to get rid off the garbage in the array of chars?

here is my code

#define MAX 100
#ifndef SYMBSIZE
 #define SYMBSIZE 1
#endif    

typedef struct tableme 
{
    char symbol[SYMBSIZE];
    int value;
    int casenmbr;
    int otherinfo;
}tabletype;
int main(int argc, char **argv)
{
    tabletype t[MAX];
    t[3].symbol[0] = 'A';

    t[0].value=1;  
    t[0].casenmbr = 7;
    t[0].otherinfo = 682;

    tabletype tabl[MAX];
    tabl[0].value = 1;
    tabl[0].symbol[0] = 'A';
    tabl[1].value = 11;
    tabl[1].symbol[0]= 'a';
    tabl[2].value = 12;
    tabl[2].symbol[0] = 'a';
    tabl[3].value = 13;
    tabl[3].symbol[0] = 'd';
    tabl[4].value = 14;
    tabl[4].symbol[0] = 'e';
    tabl[5].value = 15;
    tabl[5].symbol[0] = 'f';
    tabl[6].value = 16;  
    tabl[6].symbol[0] = 'g';
    tabl[7].value = 17;
    tabl[7].symbol[0] = 'h';
    tabl[8].symbol[0] = 'i';
    tabl[9].symbol[0] = 'x';
    t[1].symbol[0] = 'b';
    t[0].symbol[0]= 'a';
    t[2].symbol[0]= 'c';

    t[4].symbol[0]= 'g';
    printf("char at t.symbol is %s \n", t[3].symbol);

    for( x=0;x<10;x++)
    {
            printf("char at tabl[%d].symbol is %s \n",x, tabl[x].symbol);
    }
    int j;
    for(j = 0; j<5;j++)  
    {
            printf("char at t[%d].symbol is %s \n",j, t[j].symbol);
    }
    return 0;
}
  • 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-14T01:50:11+00:00Added an answer on May 14, 2026 at 1:50 am

    You have one of two possible problems. If you really just want a single character, you should be printing it with %c, not %s like this:

    printf("char at t.symbol is %c \n", t[3].symbol[0]);
    

    If you really want strings you have to define SYMBSIZE to be 1 higher than the maximum length of a symbol and put a NUL (\0) char at the end. You can do it a couple ways:

    1. tabl[6].symbol[0] = 'g'; tabl[6].symbol[1] = '\0';
    2. strcpy(tabl[6].symbol, "g");
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use VirtualBox's Shared Folders feature to enable your… May 14, 2026 at 8:28 pm
  • Editorial Team
    Editorial Team added an answer Your problem is not the field names... The problem is… May 14, 2026 at 8:28 pm
  • Editorial Team
    Editorial Team added an answer Have a look at CSS Sticky Footer. It is done… May 14, 2026 at 8:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.