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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:21:59+00:00 2026-05-21T20:21:59+00:00

I’m studying for an exam and I need some help with strings Assume the

  • 0

I’m studying for an exam and I need some help with strings

Assume the following declarations, and further assume that string.h is uncluded

char rocky[21], bw[21], boris[21];
int result;

a.) Write a scanf statement that would enable the string Beauregard to be read into rocky

my answer= scanf("%s", &rocky);

b.) Assuming that the text Beauregard is the only thing on th eline of standard input, write a statement to read in the text and store it in rocky using an alternative to scanf

my answer= gets (Beauregard);
strcpy(rocky);

c.) assuming that the text read in is Beauregard, what is the value of result after the following statement is executed?

result=strlen(rocky); 

my answer= i have no clue..

d.) what does the following statment do?

strcpy(boris, rocky);

answer= makes a copy of the string..(dont know much more than that)

e.) what does the following statement do? What are the values of rocky and bw?

strncpy(bw,rocky,3);

my answer= not a clue

help is much appreciated, and an explanation would also help 🙂

Thanks!

  • 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-21T20:22:00+00:00Added an answer on May 21, 2026 at 8:22 pm

    a. Arrays and pointers are closely related in C. In particular, the name of an array decays to a pointer to the first element of the array, so your answer should be

    scanf("%s", rocky); /* note the lack of an & in front of rocky */
    

    b. gets(Beauregard) doesn’t really make sense. The gets function reads a string from standard input (think, “keyboard”) and stores it in the character array pointed to by the argument you pass it. So you’re supposed to assume the user will type “Beauregard”, and you should read it into the rocky array with

    gets(rocky);
    

    c. strlen returns the length of the string, not including the trailing \0 character, so in this case, 10.

    d. strcpy just copies the contents of the rocky array into the boris array, so they’d both contain “Beauregard”.

    e. strncpy works like strcpy, but only copies up to n characters (where n is the last argument, so in this case, bw would contain “Bea” without a terminating null character.

    Note that several of these statements are really bad ideas in any real program. There is never a reason to use gets, for example, as any use of gets opens up security flaws. You should always use fgets instead. The scanf function can be used safely if you specify the width, but you haven’t done so here. I mention these things just in case your teacher has covered them and you’ve forgotten.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
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’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ 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
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.