Hi
I'm new to C. Here's the problem. I understand the whole concept of
pointers and can easily use it with normal non-array variables.
I want to declare a array of strings, thus multidimensiona l character
array, in my int main();
Then I want to pass this to a function that will scanf all the values.
I also want another function to display all the names but I just can
get it working.
How do yo do it?
Thanks
Riaan 2 5533
Riaan C writes: I'm new to C. Here's the problem. I understand the whole concept of pointers and can easily use it with normal non-array variables.
I want to declare a array of strings, thus multidimensiona l character array, in my int main();
Then I want to pass this to a function that will scanf all the values. I also want another function to display all the names but I just can get it working.
Fill in the blanks.
#include <stdlio.h> // exit()
void chat(char t[][20])
{
}
/*-------------------------*/
void display(char u[][20])
{
}
/*-------------------------*/
int main()
{
char s[3][20];
chat(s);
display(s);
} ri***********@t iscali.co.uk (Riaan C) writes: Hi
I'm new to C. Here's the problem. I understand the whole concept of pointers and can easily use it with normal non-array variables.
I want to declare a array of strings, thus multidimensiona l character array, in my int main();
No, more likely you want to declare an array of *pointers* to
strings. An array of strings is awkwards if the strings are of
different lengths, since you would still be forced to allocate
exactly the same amount of space for each string.
(Example of an array of strings:)
char aos[][6] = {
"Hello",
"there",
"bud"
};
As you can see, "bud" above still gets 6 bytes even though it
only uses 4 (counting the terminating null character). Compare
with:
(Example of an array of pointers-to-string:)
char *aopts[] = {
"Hello",
"there",
"bud"
};
The disadvantage to the above is that you must either point the
strings to string literals (as above), in which case you
shouldn't try to modify them; or you need to dynamically
(probably) allocate space for each and every element (and,
therefore, free() them also).
Then I want to pass this to a function that will scanf all the values. I also want another function to display all the names but I just can get it working.
I'm not sure what exactly you mean here. Please explain in more
detail what you wish to do.
-Micah This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Foxy Kav |
last post by:
Hi everyone, Im currently doing first year UNI, taking a programming
course in C++, for one project i have to create a simple array
manipulator... that i have done, but i cant figure out how to make the
ESC key quit the called function when ever the user inputs data. The
description was : ESC drops back to the main menu in case the user
gets locked up or wants to start over again, ESC should provide a fool
proof way to exit back to the...
|
by: Tarjei Romtveit |
last post by:
I'm still a newbie into C++ programming, so I got a quite foolish
string related question.
Using: Dev-cpp 4.9.9.2 (I think Dev-Cpp uses a gcc compiler of some
sort)
If i declare a char string like this:
char szString = "Hello";
|
by: Carramba |
last post by:
hi!
the code is cinpiling with gcc -ansi -pedantic. so Iam back to my question
Iam trying to make program were I enter string and serach char.
and funktion prints out witch position char is found this
is done if funktion serach_char. so far all good
what I want do next is:
return, from funktion, pointer value to array were
positions ( of found char) is stored. and print that array from main.
but I only manage to print memory adress to...
|
by: Joshua Rulz |
last post by:
Hi, i want to learn to program im quite skilled with computers and want
to learn c++. is there anyone who can teach me or tell me a good
website to learn it?
all replies will be appreciated.
|
by: aaron |
last post by:
I have a question in my class.. hoping to get some help
I need to create a program that will print
firstName middleName lastName
then their initials
User will input:
John Smith Doe
Output:
John
| |
by: Glen Dayton |
last post by:
While looking at some old code I ran across a snippet that
increments a pointer to access different members of a structure:
....
struct Badness {
std::string m_begin;
std::string m_param1;
std::string m_param2;
std::string m_end;
|
by: subramanian100in |
last post by:
Supoose we have,
int x;
int *p = &x;
int *q;
q = p + 1;
|
by: isaac2004 |
last post by:
hello, i posted with a topic like this but got no real feedback(prob
cuz of lapse in my explanation) so i am trying it again. i am trying
to set up a function that brings in a txt file and adds the file into
a 2d array. I have this to get the file.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
|
by: Stang1 |
last post by:
In the following code, can someone please explain to me what exactly
is happenening as far as accessing a 2-dimensional array with a 1-
dimensional index? What is the benifit of this?
Thanks in advance!
ck_name (name_list, max_num, item, index)
char item;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |