Discover the correct method to read user-input strings into a 2D array in C, and troubleshoot common issues that may arise during implementation. --- This video is based on the question https://stackoverflow.com/q/64852685/ asked by the user 'Ymi' ( https://stackoverflow.com/u/12982817/ ) and on the answer https://stackoverflow.com/a/64852836/ provided by the user 'Ymi' ( https://stackoverflow.com/u/12982817/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Reading a string into an 2D array of strings in C Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- How to Properly Read a String into a 2D Array of Strings in C When working with C programming, handling arrays of strings can be a bit tricky, especially when it comes to getting user input. One common task is to read multiple names from the user and store them in a 2D array. This can be confusing due to the way pointers and arrays function in C. In this guide, we will explore the steps necessary to correctly read a string into a 2D array of strings and address a mistake that can lead to program errors. Understanding the Problem Imagine you want to create a program that allows users to input multiple names separated by whitespace. You intend to store these names in a 2D array, nameptr[i][j], where i signifies the individual names and j specifies the position of the characters in each name. The ultimate goal is to develop a function that will do just that, but you may encounter some issues along the way. A Sample Implementation Let’s start by examining a sample function, which is intended to read names into a 2D array: [[See Video to Reveal this Text or Code Snippet]] Input Example The expected input from the user might look like this: [[See Video to Reveal this Text or Code Snippet]] The resulting 2D array after executing the above input should contain: [[See Video to Reveal this Text or Code Snippet]] Identifying the Issue If upon running the code, the program seems to hang or fails to print the "Test?" message, there’s a noticeable issue with the for loop condition: [[See Video to Reveal this Text or Code Snippet]] This line is problematic because size is a pointer, not the actual value of the size. Thus, you need to dereference this pointer to compare it against i. The Solution To fix the issue, change the for loop condition to properly dereference the pointer: [[See Video to Reveal this Text or Code Snippet]] With this correction, your function will now correctly read the names into the 2D array, with the size being appropriately utilized. Conclusion Understanding pointers and their dereferencing is essential when dealing with arrays in C. By making the simple adjustment from size to *size, you ensure that your loop iterates the correct number of times, allowing the program to function as intended. Thank you for reading! We hope this guide helps you effectively read strings into a 2D array in your C programs. If you have further questions or need more clarifications, feel free to engage with the community or dive deeper into the C programming documentation!