1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dybincka [34]
3 years ago
14

I have a real struggle when it comes to working with strings, whether they're arrays or pointers to strings, and I'm lost cause

when I read or watch tutos I understand them, but then I'm like a novice when I need to write actual code, what should I do?
PS: I'm using C language.
Computers and Technology
1 answer:
neonofarm [45]3 years ago
6 0
In C, you deal with a string always via a pointer. The pointer by itself will not allocate memory for you, so you'll have to take care of that.

When you write char* s = "Hello world"; s will point to a "Hello world" buffer compiled into your code, called a string literal.

If you want to make a copy of that string, you'll have to provide a buffer, either through a char array or a malloc'ed bit of memory:

char myCopy[100];
strcpy(myCopy, s);

or 

char *myCopy;
myCopy = (char*)malloc( strlen(s) + 1 );
strcpy(myCopy, s);

The malloc'ed memory will have to be returned to the runtime at some point, otherwise you have a memory leak. The char array will live on the stack, and will be automatically discarded.

Not sure what else to write here to help you...
You might be interested in
no one can succeed in his or her career without relying on others for help or opportunities. It’s best, though,
fenix001 [56]

idk good luck man idek if this is a question but if it is just go with c or b

3 0
3 years ago
Tomahawk Industries develops weapons control systems for the military. The company designed a system that requires two different
mojhsa [17]

Answer:

<em>D. Separation of duties</em>

Explanation:

Separation of duties (SoD) is a fundamental concept in internal controls and is the hardest and often the most expensive to achieve.

<em>This aim is accomplished by distributing the tasks and associated permissions among multiple people for a specific security system.</em>

7 0
3 years ago
What will you better be prepared for by learning about the animals you photograph
krek1111 [17]

D. All of the above.

Makes the most sense! :3

6 0
2 years ago
One way bloggers decide how to present information is by understanding
PSYCHO15rus [73]

I would say strong use of multimedia.

4 0
3 years ago
Read 2 more answers
HELPPP!!! ASAP *What are the purposes of a good web page?*
Brrunno [24]

I would say functional and straightforward

4 0
3 years ago
Other questions:
  • What does iSCSI stand for?
    5·2 answers
  • Skinner designed a soundproof apparatus, often equipped with a lever or bar, with which he conducted his experiments in operant
    9·1 answer
  • You maintain an RODC running Windows Server 2012 R2 at a branch office, and you want Juanita, who has solid computer knowledge,
    13·1 answer
  • What is ment by creative middle way solution
    6·1 answer
  • 2. What's the keyboard command that will allow you to "copy" text?
    8·2 answers
  • What would you recommend for data segregation if using cloud software
    12·2 answers
  • Match the personality traits with their description
    9·2 answers
  • Can someone help me get spotify premium
    7·2 answers
  • For a parking application that lets you pay for parking via your phone, which of these is an example of a functional requirement
    8·1 answer
  • Explain set associative mapping<br>​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!