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
Explain the difference between overexposed vs. underexposed images?
hichkok12 [17]

Answer:

If a photo is too dark, it is underexposed. Details will be lost in the shadows and the darkest areas of the image. If a photo is too light, it is overexposed. Details will be lost in the highlights and the brightest parts of the image.

3 0
2 years ago
Read 2 more answers
What are the data types used in C programming with examples
Zepler [3.9K]
I don’t really understand what you are trying to ask. Try posting a picture along with your question
5 0
3 years ago
The __________ is a worldwide collection of networks that links millions of businesses, govenment agencies, educational institut
Vlad [161]
<span>The INTERNET is a worldwide collection of networks that links millions of businesses, government agencies, educational institutions, and individuals.</span>
5 0
3 years ago
What does a file association specify?
Olenka [21]

Answer:

The answer is D

Explanation:

file association associates a file with an application capable of opening that file. More commonly, a file association associates a class of files with a corresponding application.

4 0
2 years ago
Read 2 more answers
Recently, a serious security breach occurred in your organization. An attacker was able to log in to the internal network and st
natulia [17]

Answer: Geotagging was enabled on her smartphone

Explanation:

The security weakness that is the most likely cause of the security breach is that geotagging was enabled on the vice president's smartphone.

Geotagging, occurs when geographical identification metadata are added to websites, photograph, video, etc. Geotagging can be used to get the location of particular place.

In this case, since geotagging was enabled on her smartphone, it was easy for the attacker to locate her house.

8 0
3 years ago
Other questions:
  • ___ refers to all aspects of managing and processing information using computers and computer networks
    13·1 answer
  • What is requirement analysis
    8·1 answer
  • Tammy is preparing to give a presentation. she would like to view information that will remind her what to say to her audience b
    10·1 answer
  • What commands would return all the rows and columns in the ProductCategory table?
    7·1 answer
  • What are two types of formulas in Excel
    13·2 answers
  • Fedora operating system
    9·1 answer
  • S.B. manages the website for the student union at Bridger College in Bozeman, Montana. The student union provides daily activiti
    7·1 answer
  • List at least 5 professions for people working in the Information/Communication<br> fields.
    10·1 answer
  • Which statement is true about hacking?
    11·2 answers
  • DERECTIONS: Identify all the computer software that you need for the following entrepreneurial activities. Refer your answer fro
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!