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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:42+00:00 2026-06-15T10:45:42+00:00

I am using the function gets() to retrieve string input from the user. I

  • 0

I am using the function gets() to retrieve string input from the user. I then store that string into a char array, char transdestmp[DESMAX], where DESMAX is 31. If the variable_name is greater than 30 chars, then ask the user to renter another string. Else, copy the string using strcpy(), into a 2 dimensional array char – acctdes[31][20].

accttitle recieves transdestmp[DESMAX]

void accttitle(char descr[DESMAX])
{
    printf("\nEnter title for new account %d: ", transinpt);
    gets(descr);
    while(strlen(descr)>DESMAX){
        printf(" **Title entered is longer than 30 characters\n");
        printf(" Please reenter : ");
        gets(descr);
    }
    strcpy(acctdes[transcntr],descr);
    printf("---->vacctdes[transcntr]: %s\n", acctdes[transcntr]);
    printf("---->vacctdes[transcntr-1]: %s\n", acctdes[transcntr-1]);
}

For some reason when I input a long string, and then enter another string, apart of the second string acctdes[1] overwrites the other string stored in acctdes[0].

for example,

First input:
acctdes[0] = “This is a long string”

It works…

Second input
acctdes[1] = “monkey”

It works…

but then, it seems that when I output acctdes[0], acctdes[0] has some of the value from acctdes[1]… like output – This is a long monk…

Please let me know if you would like more information. Thanks in advance.

  • 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-15T10:45:43+00:00Added an answer on June 15, 2026 at 10:45 am

    You have the dimensions on your array reversed. Try acctdes[20][31].

    The reason the strings bleed into each other is because C lays out a two-dimensional array as one long block of memory. When you do acctdes[2] its really doing pointer arithmetic under the hood like *(acctdes + (31 * 2)) to skip over the first part of the memory block to get to your third element. So if one string writes past its bounds, it will end up in the next string.

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

Sidebar

Related Questions

I need to encrypt a string using MySQL's AES_ENCRYPT function, then attach that encrypted
I'm trying to retrieve records from the mySQL-database but nothing gets selected. I'm using
Im using node.js+express+mongodb+mongoose, trying to retrieve user from database by custom ids, page returns
I'm using C++ map to implemented a dictionary in my program. My function gets
I'm using login function in my site with session. This session of mine gets
I am using jQuery(Latest release) and have a function called calculate() which gets called
I'm using Python and PyGTK. I'm interested in running a certain function, which gets
I'm trying to retrieve images from a folder using glob() and i want it
So I have a Retrieve() function, which either gets me an object or a
I am trying to retrieve some rows from the database using simple SELECT statement

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.