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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:27:53+00:00 2026-05-12T09:27:53+00:00

I will be coaching an ACM Team next month (go figure), and the time

  • 0

I will be coaching an ACM Team next month (go figure), and the time has come to talk about strings in C. Besides a discussion on the standard lib, strcpy, strcmp, etc., I would like to give them some hints (something like str[0] is equivalent to *str, and things like that).

Do you know of any lists (like cheat sheets) or your own experience in the matter?

I’m already aware of the books for the ACM competition (which are good, see particularly this), but I’m after tricks of the trade.

Thank you.

Edit: Thank you very much everybody. I will accept the most voted answer, and have duly upvoted others which I think are relevant. I expect to do a summary here (like I did here, asap). I have enough material now and I’m certain this has improved the session on strings immensely. Once again, 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-12T09:27:54+00:00Added an answer on May 12, 2026 at 9:27 am

    It’s obvious but I think it’s important to know that strings are nothing more than an array of bytes, delimited by a zero byte.
    C strings aren’t all that user-friendly as you probably know.

    • Writing a zero byte somewhere in the string will truncate it.
    • Going out of bounds generally ends bad.
    • Never, ever use strcpy, strcmp, strcat, etc.., instead use their safe variants: strncmp, strncat, strndup,…
    • Avoid strncpy. strncpy will not always zero delimit your string! If the source string doesn’t fit in the destination buffer it truncates the string but it won’t write a nul byte at the end of the buffer. Also, even if the source buffer is a lot smaller than the destination, strncpy will still overwrite the whole buffer with zeroes. I personally use strlcpy.
    • Don’t use printf(string), instead use printf(“%s”, string). Try thinking of the consequences if the user puts a %d in the string.
    • You can’t compare strings with
      if( s1 == s2 )
                  doStuff(s1);

      You have to compare every character in the string. Use strcmp or better strncmp.

      if( strncmp( s1, s2, BUFFER_SIZE ) == 0 )
               doStuff(s1);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are about to start a new project. It will be a group of
Will the Hibernate caching(1st, 2nd, or Query) work when I use JdbcTemplate? I got
I would like to create a caching system that will bypass some mechanisms in
Will the following code cause a ConcurrentModificationException or other side effects? ArrayList<String> newList =
Will my windows-7, command prompt allow me to filter memory logcat messages for my
Will a thread stop if I send it SIGTSTP signal? Or in other words
Will the events that I added to the global event bus deleted by calling
Will the element be visible even for a blink of an eye If it
Will the following media queries behave exactly same on mobile devices and computers or
Will Java 8 support pattern matching like Scala and other functional programs do? I'm

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.